Download
%!PS-Adobe-3.0
%%Creator: Nick
%%Title: combsort
%%LanguageLevel: 2
%%Pages: 1
%%Orientation: Portrait
%%DocumentMedia: Letter 612 792 0 () ()
%%PageMedia: Letter

%%Page: 1 1
(y) 550 store
5 dict begin

/concat {
  1 index length 1 index length add
  string
  dup
  4 3 roll
  dup length
  5 1 roll
  0 exch
  putinterval
  dup 4 1 roll
  3 1 roll
  putinterval
} bind def

/arrayToString
{
  ()
  (\[ )
  3 2 roll
  {3 1 roll concat exch toString concat (, )} forall
  pop
  ( \]) concat
} bind def

/toString {
  dup type (arraytype) cvn eq {arrayToString} {200 string cvs} ifelse
} bind def

/puts {
  100 (y) load dup 11 sub (y) exch store moveto
  /Helvetica findfont
  10 scalefont setfont
  0 setgray
  toString show
} bind def

/newGap {
  (gap) load
  10 mul 13 idiv
  dup 9 eq 1 index 10 eq or {drop 11} if
  dup 1 lt {pop 1} if
  (gap) exch store
} bind def

/combsort {
  dup (a) exch store length (gap) exch store
  {
    newGap
    (swapped) false store
    0 1 (a) load length 1 sub (gap) load sub
    {
      dup (gap) load add
      (j) exch store (i) exch store
      (a) load (i) load get
      (a) load (j) load get gt
      {
	(a) load (j) load get
	(a) load (i) load get
	(a) load (j) load 3 2 roll put
	(a) load (i) load 3 2 roll put
	(swapped) true store
      } if
    } for
    (gap) load 1 eq (swapped) load not and {exit} if
  } loop
  (a) load
} bind def


(Welcome to Nick's combsort in Postscript!) puts
() puts

(Original array:) puts
[ 1 6 5 3 8 6 9 7 2 4 0 ]
dup puts
() puts
(Sorted array:) puts
combsort puts

showpage
end