[Home]
[Chapter]
[Contents]
[Previous Algorithm]
[Next Algorithm]


Linear insertion sort


procedure sort( var r : ArrayToSort; lo, up : integer ); var i, j : integer; tempr : ArrayEntry; flag : boolean; begin for i:=up-1 downto lo do begin tempr := r[i]; j := i+1; flag := true; while (j<=up) and flag do if tempr.k > r[j].k then begin r[j-1] := r[j]; j := j+1 end else flag := false; r[j-1] := tempr end end;

C source (412.sort.c) Pascal source (412.sort.p)



© Addison-Wesley Publishing Co. Inc.