X
xiaoshun
Unregistered / Unconfirmed
GUEST, unregistred user!
function binsch(A,low,high,K);integer;
{A和K为f变参,low和high为直参,low和high用以分别表示当前查找区间的下界和上界,初值应该分别为1和n}
var
low:integer;
high:integer;
mid:integer;
begin
low:=1;
high:=n;
//查找区间的下界和上界的初值
while low<=highdo
begin
mid:=(low+high) div 2;
if A[mid].key=k;
then
begin
return(mid);
//查找成功返回
end;
if A[mid].key>k;
then
binsch;=binsch(A,low,mid-1,k);
//在左子表上继续查找
if A[mid].key<k;
binsch;=(A,min+1,high,k);
//在右子表上继续查找
end;
else
binsch:=0 //查找失败
end;
{A和K为f变参,low和high为直参,low和high用以分别表示当前查找区间的下界和上界,初值应该分别为1和n}
var
low:integer;
high:integer;
mid:integer;
begin
low:=1;
high:=n;
//查找区间的下界和上界的初值
while low<=highdo
begin
mid:=(low+high) div 2;
if A[mid].key=k;
then
begin
return(mid);
//查找成功返回
end;
if A[mid].key>k;
then
binsch;=binsch(A,low,mid-1,k);
//在左子表上继续查找
if A[mid].key<k;
binsch;=(A,min+1,high,k);
//在右子表上继续查找
end;
else
binsch:=0 //查找失败
end;