/frames 16 def %include /u/rs/book3/pslib/tools.ps %include /u/rs/book3/pslib/example.ps /bubblesort { 1 1 N 1 sub { dup N 1 sub exch -1 exch 1 add {dup 1 sub compareswap} for N 1 sub SUBFILEx } for } def LL RR SUBFILE bubblesort LL RR SUBFILE ---------------------------- T 147pt Bubble sorting example Large keys percolate over to the left in bubble sort. Each key is exchanged with the one on its right until a large one is encountered. In particular, the largest key makes it to the end of the file on the first pass: First the {\F S} moves to the {\F T}, then the {\F T} to the {\F X}, then the {\F X} to the end of the file. Then the next largest makes it to its final position on the second pass, etc.