-




( ) - 3


readin

end.

. ( , .). . , ( ) .

L:=0; R:=N; while L<R do

begin

m:=(L+R) div 2;

if a[m]<X then L:=m+l else R:=m;

end;.

, =13, :

[0]=1; [1]=3; [2]=4; [3]=7; [4]=8; [5]=9; [6]=13; [7]=20; [8]=23.

:

1 3 4 7 8 9 13 20 23 -

0 1 2 3 4 5 6 7 8-

L m R

L m R

a[m]=x => m = 6

.

43

program poisk2; (* *)

const N=8;

type item= integer;

var a: array[0..n] of item; i, L, R, m:integer; x: item; f:

boolean;

begin

(*

*)

for i:=0 to N do

begin write( '

a[',i, '1= '); readln(a[i])

end;

writeln; write( '

= '); readln(x);

(* *)

L:=0; R:=N; f:=false;

repeat m:=(L+R) div 2; if a[m]=X then f:=true;

if a[m]<X then L:=m+l

else R:=m;

writeln(m,L,R);

until (L>=R)or(f);

(* *)

if

f then write(' ',m, ' ') else write(' ');

readln

end.

.

: