heapsort(S,m) is
{@$ S(0..m-1) \in Int \land m\gt 0$@}
@$\bb$@ Var i @$\in$@ Int;
   initially B=S @$ \land $@ i=m-1
   heapbuild(S,m)
  ;do  {@$P$@}
     i@$>$@0 @$\rightarrow$@  S.j,S.i,i:=S.i,S.j,i-1
            ;heapsink(S,i)
   od
   @$\{P \land \neg G\}$@
   @$\{R\}$@
@$\be$@




