Explanation

The ``if'' statement swaps adjacent elements A[i] and A[i+1] in the array if they are out of order.

The ``for'' loop, sweeps through the list swapping adjacent elements as it goes.

The ``while'' loop executes the ``for'' loop repeatedly until it makes no swaps.


next up previous
Next: Step 2: Prove Correctness Up: BUBBLESORT Previous: Step 1: Develop Algorithm