/frames 14 def /figflag 1 def %include /u/rs/book3/pslib/tools.ps %include /u/rs/book3/pslib/example.ps /partition { /r exch def /l exch def /v A r get def /j r def /i l 1 sub def l r SUBFILE r frame 1 add PTmark nextframe { /oldi i def /oldj j def { /i i 1 add def A i get v ge { exit } if } loop oldi 1 add i SUBFILE { /j j 1 sub def A j get v le { exit } if } loop j oldj 1 sub SUBFILE j i lt { exit } if j i swap l i j r SUBFILEtwo nextframe } loop i r swap nextframe l r SUBFILE i frame 1 add PTmark } def LL RR partition -------------------- T 10.25pc Partitioning example Quicksort partitioning begins by choosing a partitioning element, in this case the rightmost element, the {\F E}. Then the process involves scanning from the left, stopping at larger elements, and from the right, stopping at smaller elements. First, the scan from the left stops at the {\F S}, then the scan from the right stops at the {\F A}, and then these two are exchanged. Next, the scan from the left stops at the {\F O}, then the scan from the right stops at the {\F E}, and then these two are exchanged. Next, the pointers cross. The scan from the left stops at the R, and the scan from the right stops at the {\F E}. To finish the process, the paritioning element (the {\F E} at the right) is exchanged with the {\F R}.