/frames 10 def %include /u/rs/book3/pslib/tools.ps %include /u/rs/book3/pslib/example.ps /hsortA { /incr exch def 0 1 incr 1 sub { incr add incr N 1 sub { /lll exch def lll incr neg incr { /xxx exch def xxx incr sub xxx compare { exit } if xxx xxx incr sub compareswap /xxx xxx incr sub def } for xxx lll SUBFILEx } for nextframe } for } def /SUBFILEx { /rr exch def /ll exch def LL 1 RR { dup dup dup ll incr sub le exch rr gt or exch rr exch sub incr mod 0 ne or { SqGrL }{ SqWhL } ifelse exch PT } for nextframe } def /hsortB { /incr exch def incr 1 N 1 sub { /lll exch def lll incr neg incr { /xxx exch def xxx incr sub xxx compare { exit } if xxx xxx incr sub compareswap /xxx xxx incr sub def } for xxx lll SUBFILEx } for } def 4 hsortB ---------------------------- T 20pc Interleaving 4-sorts. One way to 4-sort a file \itpc{top} is to first insertion-sort the subfile at positions 1, 5, 9, $\ldots$ , then insertion-sort the subfile at positions 2, 6, 10, $\ldots$ , then insertion-sort the subfile at positions 3, 7, 11, $\ldots$ , then insertion-sort the subfile at positions 4, 8, 12, $\ldots$. But the three subfiles are independent, so the same result can be achieved by inserting each element into position into its subfile, going back four at a time \itpc{bottom}. Taking the rows in the bottom diagram in the order 1 5 9 2 6 10 3 7 11 4 8 gives the top diagram.