function search( key : typekey; var r : dataarray ) : integer;
var j : integer;
begin
if n > 1 then
begin
{*** initial probe location ***}
j := trunc( (key-r[1].k) / (r[n].k-r[1].k) * (n-1) ) + 1;
if key < r[j].k then
while (j>1) and (keyr[j].k) do j := j+1
end
else j := 1;
if r[j].k = key then search := j {*** found(r[j]) ***}
else search := -1; {*** notfound(key) ***}
end;
|