program p181217; uses Windows; const MAX = 100*1000; var POLE: array[1..MAX] of integer; pocet: integer; function PoleObsahujeHodnotu( x: integer ): boolean; var i: integer; begin PoleObsahujeHodnotu := TRUE; for i:=1 to pocet do if POLE[i]=x then exit; PoleObsahujeHodnotu := FALSE end; procedure PridejHodnotuDoPole( x: integer ); begin if PoleObsahujeHodnotu( x ) then exit; Inc( pocet ); POLE[ pocet ] := x end; type PPrvek = ^TPrvek; TPrvek = record x: integer; L,P: PPrvek end; function BVSObsahuje( koren: PPrvek; x: integer ): boolean; begin if koren=NIL then BVSObsahuje := FALSE else if x = koren^.x then BVSObsahuje := TRUE else if x < koren^.x then BVSObsahuje := BVSObsahuje( koren^.L, x ) else BVSObsahuje := BVSObsahuje( koren^.P, x ) end; procedure PridejHodnotuDoBVS( var koren: PPrvek; x: integer ); begin if koren=NIL then begin new(koren ); koren^.x := x; koren^.L := NIL; koren^.P := NIL; Inc( pocet ) end else if x=koren^.x then exit else if xNIL do begin predp := p; p := p^.P end; tenhle^.x := p^.x; q := p; if predp=NIL then tenhle^.L := p^.L else predp^.P := p^.L end; dispose( q ) end; procedure VytiskniBVS( koren: PPrvek ); begin if koren<>NIL then begin VytiskniBVS( koren^.L ); write( koren^.x,' ' ); VytiskniBVS( koren^.P ) end; end; var bvs: PPrvek; begin bvs := NIL; PridejHodnotuDoBVS( bvs, 10 ); PridejHodnotuDoBVS( bvs, 20 ); PridejHodnotuDoBVS( bvs, 15 ); PridejHodnotuDoBVS( bvs, 7 ); PridejHodnotuDoBVS( bvs, 5 ); VytiskniBVS( bvs ); readln; while bvs<>NIL do begin VymazZBVS( bvs ); VytiskniBVS( bvs ); readln; end; readln; end. var N,i,k: integer; start: QWord; bvs: PPrvek; begin for k:=1 to 20 do begin N := k*2000; pocet := 0; bvs := NIL; start := Windows.GetTickCount; for i := 1 to N do //PridejHodnotuDoPole( random( MAXINT ) ); //PridejHodnotuDoBVS( bvs, random( MAXINT ) ); PridejHodnotuDoBVS( bvs, i ); writeln( N:6, pocet: 6, (Windows.GetTickCount - start):6 ); end; readln; end.