USES CRT; type TKey = integer; PNode = ^TNode; TNode = record key : TKey; left,right : PNode; end; {-----------------------------------} PROCEDURE make(var p : PNode; x : Tkey); begin new(p); p^.key:=x; p^.left:=nil; p^.right:=nil; end; PROCEDURE insert(var p : PNode; h : integer); begin make(p^.left,Random(10){h}); make(p^.right,Random(10){h}); if h > 1 then begin insert(p^.left,h-1); insert(p^.right,h-1); end; end; {--------------------------------------------------------} PROCEDURE inorder(var p : PNode); begin if p<>nil then begin inorder(p^.left); Write(p^.key,' '); inorder(p^.right); end; end; {-----------------------------------------------------} PROCEDURE poisk(var p : PNode; x : TKey; var k : Integer); begin if p<>nil then begin if p^.key = x then k:=k+1; poisk(p^.left,x,k); poisk(p^.right,x,k); end; end; {******************************************} {--------------------------------------------------------} var p : PNode; x : Tkey; h,kol : integer; tree : PNode; begin clrscr; h:=2; tree:=nil; make(tree,Random(10){0}); insert(tree,h); Writeln('obratnij obhod dereva: '); inorder(tree); Writeln; Writeln; Writeln('vvedite iskomij kluth : '); Readln(x); kol:=0; poisk(tree,x,kol); Writeln; Write('thislo vhogdenij klutha ',x,': ',kol); readln; end.