PASCAL的二分法

procedure midsearch(num:longint);
var top,bot,mid:longint;
begin
top:=0;bot:=nk+1;
if bot-top<=1 then mid:=bot;
while bot-top>1 do
begin
mid:=(top+bot) div 2;
if list[num]<=list[res[mid]] then
top:=mid
else bot:=mid;
end;
res[bot]:=num;
rec[num]:=res[bot-1];
if bot=nk+1 then inc(nk)
end;

你可能感兴趣的:(pascal)