/frames 16 def %include /u/rs/book3/pslib/tools.ps %include /u/rs/book3/pslib/example.ps /compare {/i exch def /j exch def A i get A j get gt j i 3 -1 roll} def /selectionsort {0 1 N 2 sub { dup /min exch def /xxx exch def xxx 1 add 1 N 1 sub {min compare { pop /min exch def} {pop pop} ifelse} for min frame 1 add PTmark xxx min swap xxx 1 add RR SUBFILEx } for } def LL RR SUBFILE selectionsort LL RR SUBFILE ---------------------------- T 11.75pc Selection sorting example The first pass of selection sort has no effect because there is no element in the array smaller than the {\F A} at the left. On the second pass, the other {\F A} is the smallest remaining element, so it is exchanged with the {\F S} in the second position. Then the {\F E} near the middle is exchanged with the {\F O} in the third position on the third pass, then the other {\F E} is exchanged with the {\F R} in the fourth position on the fourth pass, and so forth.