% % Copyright (C) 1988 by Bobo Leffler. All rights reserved. % This program is provided for unrestricted use, provided that this % copyright message is preserved. There is no warranty, and no author % or distributer accepts responsibility for any damage caused by this % program. % /bubblesort { % array => array (sort array with bubble sort) 10 dict begin /a exch def a length 2 sub -1 -1 { % for j=n-2 step -1 until 0 do 0 1 3 -1 roll { % for i=0 step 1 until j do /i exch def a i 1 add get a i get lt { % if a[i+1] < a[i] then a i get % a[i] a i 1 add get a i 3 -1 roll put % a[i] = a[i+1] a i 1 add 3 -1 roll put % a[i+1] = a[i] } if } for } for a end } def