0.0 General‎ > ‎General Notes‎ > ‎

Notes- Bubble Sort

Caution:
Remember what type of data type of the index of the array is.
Algorithm #1:
Pseudo-code for the Bubble Sort

For each Pass from 1 to the size the number of elements to be sorted less 1
For each element from 1 to number of elements less Pass
If the current element is greater than the next element 
SWAP the two elements
End if
End for
End for

Algorithm #2:
Pseudo-code for the Bubble Sort with an early exit

Set SwapMade to True
Set pass to 0
Loop while SwapMade
Increase pass by one
Set SwapMade to False
For each element from 1 to number of elements less Pass
If the current element is greater than the next element 
SWAP the two elements
Set SwapMade to True
End if

End for
End loop

Comments