FANDOM


Binary search for array that is sorted in ascending order:
function TSplitList.inc_search(const Val: TDataType; var i, j: longint): longint;
var
  tmp_dat: TDataType;
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 }
Binary search for array that is sorted in descending order:

function TSplitList.dec_search(const Val: TDataType; var i, j: longint): longint; var

 tmp_dat: TDataType;

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)

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.