No. of comparisons: 0 No. of swaps: 0
while(swapped)
swapped = false
for x = 0 to
length(list)-1
if list[x]
> list[x+1]
swap(list[x], list[x+1])
swapped =
true
if(swapped ==
false)
break
for x = length(list)-2
to 0
if list[x]
> list[x+1]
swap(list[x], list[x+1])
swapped =
true
SHORT EXPLANATION
------------------
1. Starting at index 0, compare the current element with
the next element
- If the current element is greater than the next element,
swap them
- If the current element is less than the next element, move
to the next element
2. Repeat Step 1 until at the last index
3. Starting at index length(list)-2, compare the current
element with the next element
- If the current element is greater than the next element,
swap them
- If the current element is less than the next element, move
to the prev. element
4. Repeat Step 3 until at the first index
5. Start over from 1. until the list is sorted