function iteration_search arr array of integer integer begin length ar

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
function iteration_search(arr: array of integer): integer;
begin
L := 1;
H := length(arr);
while(L <= H) do begin
p := ceil((L + H) / 2);
if(k = arr[p]) then begin
BS := p;
break;
end;
if(k < arr[p]) then begin
H := p - 1;
end else begin
L := p + 1;
end;
end;
BS := 0;
result := BS;
end;