顺序查找和二分查找
{线性的顺序查找}
function seqSearch(sArr: array of Integer;aCount: Integer;const index: Integer):Integer;
var
i: Integer;
begin
Result := -1;
for i := 0 to aCount do
if sArr[i]=index then
begin
Result := i;
Break;
end;
end;
{对数性的二分查找}
function binarySearch(sArr: array of Integer;aCount: Integer;const index: Integer):Integer;
var
L,R,M: Integer;
begin
L:=0;
R:=aCount;
Result := -1;
while(L<=R)do
begin
M:=(L+R) div 2;
if sArr[M]=index then
begin
Result := M;
Exit;
end
else if sArr[M] < index then
L:=M+1
else
R:=M-1;
end;
end;