home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 February
/
Chip_2000-02_cd.bin
/
zkuste
/
Delphi
/
navody
/
tt
/
binsearch.txt
next >
Wrap
Text File
|
1999-11-22
|
1KB
|
37 lines
function FoundByBinarySearch
( LowIdx,
HighIdx : LongInt;
var Result : LongInt;
const GoalIs : CompareFunc;
var Data;
var Goal
) : Boolean;
var
CompVal : CompareResults;
begin
FoundByBinarySearch := FALSE;
if HighIdx < LowIdx then
Exit;
Result := LowIdx + ((HighIdx-LowIdx) div 2);
CompVal := GoalIs(Result, Data, Goal);
if CompVal = BinEqual then
FoundByBinarySearch := TRUE
else if (LowIdx < HighIdx) then
begin
if CompVal = BinLess then
HighIdx := Result-1
else {CompVal = BinGreater}
LowIdx := Result+1;
FoundByBinarySearch := FoundByBinarySearch(
LowIdx, HighIdx, Result, GoalIs, Data, Goal)
end
else if (CompVal = BinLess) then
Dec(Result)
end; { function FoundByBinarySearch }