function BinarySearch(List: TStringList; const str: string): Integer;
var
L,R,M: Integer;
CompareResult: Integer;
begin
Result := -1;
L := 0;
R := List.Count - 1;
while L <= R do
begin
M := (L + R) div 2;
CompareResult := CompareText(List[M], str);
if CompareResult < 0 then
L := M + 1
else
if CompareResult > 0 then
R := M - 1
else
begin
Result := M;
Exit;
end;
end;
end;
二分查找
最新推荐文章于 2024-07-13 15:17:36 发布