program progrtetelek_rekurzioval; {PM4 - 2001.02.20.} {Sz. P.} uses stopper; const nmax=10000; {y=maxint/2;} type ttomb=array[1..nmax] of longint; Tindex=integer; var x:ttomb; n:integer; y:integer; foindex:tindex; fovan:boolean; folytat:char; ido,ido1,ido2:real; function eldontesRek(n:integer):boolean; {specif: be: NEH, xEH* 1 ki: vanEL ef:0 uf: van=eldont(n,x) def: eldont: NxH -> L / hamis, ha n=0 eldont(n){ igaz, ha x(n)=Y \ eldontes(n-1,x)} begin if n=0 then eldontesRek:=false else if (x[n]=y) then eldontesRek:=true else eldontesRek:=eldontesRek(n-1); end; function eldontesCk(n:integer):boolean; Var i:Integer; begin i:=1; while ( (i<=n) and (x[i]<>y)) do inc(i); eldontesCk:=((i Tindex / 0 ha n=0; kereses(n){ n ha x(n)=y \ kereses(n) kul.} begin if n=0 then begin van:=false; index:=0; end else if x[n]=y then begin index:=n; van:=true; end else keresesRek(n-1,index,van); end; procedure keresesCk(n:integer; var index:tindex; van:boolean); var i:integer; begin i:=1; while ( (i<=n) and (x[i]<>y)) do inc(i); van:=((i Tindex kozepe:=round((eleje+vege)/2) / 0 ha n=0 / n ha x[n]=y kereses(eleje,vege){ ha x[kozepe]>y then eleje:=kozepe; kereses(eleje,vege) \ ha x[kozepe]y) ) then begin van:=false; index:=0; end else if x[kozepe]=y then begin index:=kozepe; van:=true; end else if x[kozepe]>y then begin logkeresRek(kozepe,vege,index,van); end else if x[kozepe]y) or (eleje<>vege) ) do begin kozepe:=round(trunc(eleje+vege)/2); if (y>x[kozepe]) then eleje:=kozepe else if (y0) then tombmaxertekbe(n); end; procedure miazy(var y:integer); var be:string; ok:integer; begin write('Mi legyen a keresett elem erteke? '); readln(be); val(be,y,ok); if (ok<>0) then miazy(y); end; procedure tombfeltolt(var x:ttomb; const n:integer); var i:integer; begin for i:=1 to n do x[i]:=i; end; procedure indul; begin tombmaxertekbe(n); tombfeltolt(x,n); miazy(y); writeln('A keresett ertek: ',y); writeln; writeln('Ora indul (Rek)...'); indit(ido1); writeln('Eldontes(rek): ',eldontesRek(n)); keresesRek(n,foindex,fovan); write('Van: ',fovan); writeln(' - Ha van, a sorszam /normal-rek/: ',foindex); logkeresRek(1,n,foindex,fovan); write('Van: ',fovan); writeln(' - Ha van, a sorszam /log-rek/: ',foindex); writeln('Ora all (Rek)...'); allit(ido1); writeln; writeln('Ora indul (Ck)...'); indit(ido2); writeln('Eldontes(ck): ',eldontesCk(n)); keresesCk(n,foindex,fovan); write('Van: ',fovan); writeln(' - Ha van, a sorszam /normal-ck/: ',foindex); logkeresCk(1,n,foindex,fovan); write('Van: ',fovan); writeln(' - Ha van, a sorszam /log-ck/: ',foindex); writeln('Ora all (Ck)...'); allit(ido2); ido:=ido2-ido1; writeln('Kulonbseg: ',ido); write('Folytassam? '); readln(folytat); if upcase(folytat)<>'N' then indul; end; {mekkora a tomb, feltolti-e? fv-hivas alt.a rendezettseg mindegy (kiv. logaritmikus kereses) eldontes, kereses, log.kereses, maxkiv.} begin indul; end.