Type fun=function (j. word):Boolean;
Function fa(j. word):Boolean; far; Begin fa:= A fj] < x l End;
Functionfb(j:word).Boolean; far; Begin fb:= A[j] > x2 End;
Procedure Search(f 1 f2:fun; L. integer; var m,k,usp:word);
Var i,j,kk:word;
Begin usp:=l; i:=m+l; kk:=k;
I fL < > l Then
Begin [f2 funksiyasi b o 'yicha binar izlash sikli: }
Repeat j :—(i+kk) div 2; Iff2(j) Then kk: =/ Else i: =j+ /
Until i=kk; Ifi=m+1 Then usp:=0
Else If (L > I) A n d fl(i-l) Then usp:=0
End; fi - argumentdga engyaqin katta kalitli topilgan yozuv
nomeri} If usp = 0 Then Exit;
If (L > 2) Or (L = 1) Then
Begin i:=kk-l; {izlanayotgan yozuvlarni pastdan chegaralaydigan
yozuv topiladi;fl funksiyasi bo ‘yicha binar izlash sikli}
Repeat j:= (m + i+ l) div 2; IfflQ) Then m:=j Else i:=j-l
Until m=i;
lfL = l Then Begin Ifm-k-1 Then usp:—0; i:= m+1 End
End
Else If(L=-l) Or Not f l( i- l) Then i:-i-l;
Do'stlaringiz bilan baham: |