Wikia

Delphi Programming

Binary Search

2,918pages on
this wiki
Talk0
function TSplitList.inc_search(const Val: TDataType; var i, j: longint): longint;
begin
  repeat
    result:= (i+j) shr 1;
    tmp_dat:= Val -ary_data[result];
    if tmp_dat = 0 then
      EXIT
    else
      if tmp_dat > 0 then
        i:= result +1
      else
        j:= result -1;
  until i > j;
  Result:= -1;
end;{ inc_search }
function TSplitList.dec_search(const Val: TDataType; var i, j: longint): longint;
begin
  repeat
    result:= (i+j) shr 1;
    tmp_dat:= Val -ary_data[result];
    if tmp_dat = 0 then
      EXIT
    else
      if tmp_dat > 0 then
        i:= result -1
      else
        j:= result +1;
  until i < j;
  result:= -1;
end;{ dec_search }

--NNN nmanca 20:25, 13 August 2008 (UTC)

Around Wikia's network

Random Wiki