Jul 14, 2024
n tracks the range of elements to check (initially set to the length of the dataset).swapped flag indicates if a swap has occurred (initially set to true).n > 0 and swapped is true.
swapped to false.n by 1 each iteration.n-1).
swapped to true.n = length(items)
swapped = true
while n > 0 and swapped == true
swapped = false
n = n - 1
for index in range(0 to n-1)
if items[index] > items[index + 1]
swap(items[index], items[index + 1])
swapped = true
items = ['Florida', 'Georgia', 'Delaware', 'Alabama', 'California']
n = len(items)
swapped = True
while n > 0 and swapped:
swapped = False
n -= 1
for i in range(n):
if items[i] > items[i + 1]:
temp = items[i]
items[i] = items[i + 1]
items[i + 1] = temp
swapped = True
print(items)