Linear probing sort
 

procedure sort( var r : ArrayToSort; lo, up : integer );

var i, j : integer;
r1 : ArrayToSort;
begin
r1 := r;
for j:=lo to UppBoundr do r[j].k := NoKey;
for j:=lo to up do begin
i := phi(r1[j].k,lo,m);
while r[i].k <> NoKey do begin
if r1[j].k < r[i].k then begin
r1[j-1] := r[i];
r[i] := r1[j];
r1[j] := r1[j-1]
end;
i := i+1;
if i > UppBoundr then Error
end;
r[i] := r1[j]
end;
i := lo-1;
for j:=lo to UppBoundr do
if r[j].k <> NoKey then begin
i := i+1;
r[i] := r[j]
end;
for j:=i+1 to UppBoundr do r[j].k := NoKey;
end;



sort( r, lo, up )
ArrayToSort r;
int lo, up;

{ArrayToSort r1;
int i, j, uppr;
uppr = up + (UppBoundr-up)*3/4;
for (j=lo; j<=up; j++) r1[j] = r[j];
for (j=lo; j<=UppBoundr; j++) r[j].k = NoKey;
for (j=lo; j<=up; j++) {
for ( i=phi(r1[j].k,lo,uppr); r[i].k != NoKey; i++) {
if ( r1[j].k < r[i].k ) {
r1[j-1] = r[i];
r[i] = r1[j];
r1[j] = r1[j-1];
};
if ( i > UppBoundr ) Error;
}
r[i] = r1[j];
};
for (j=i=lo; j<=UppBoundr; j++)
if ( r[j].k != NoKey )
r[i++] = r[j];
while ( i <= UppBoundr )
r[i++].k = NoKey;
};

(c) Shilpa Sayura Foundation 2006-2017