 | Algorithm B (Bubble sort).
Records R1, ..., RN are rearranged in place;
after sorting is complete their keys will be in
order, K1 <= ··· <= KN.
 | [Initialize BOUND.]
Set BOUND <- N.
(BOUND is the highest index for which the record
is not known to be in its final position; thus we
are indicating that nothing is known at this point.)
|
 | [Loop on j.] Set t <- 0. Perform
step B3 for j = 1, 2, ..., BOUND-1,
and then go to step B4. (If BOUND = 1,
this means go directly to B4.)
|
 | [Compare/exchange Rj : Rj+1.]
If Kj > Kj+1, interchange
Rj <-> Rj+1 and
set t <- j.
|
 | [Any exchanges?] If t = 0, terminate the
algorithm. Otherwise set BOUND <- t
and return to step B2.
|
|