Program P130; uses crt; type Arbore=^Nod; Nod=record Info : integer; St, Dr : Arbore end; var T : Arbore; {radacina } r:integer; s:integer; function Arb : Arbore; {crearea arborelui binar } var R : Arbore; s : integer; begin readln(s); if s=0 then Arb:=nil else begin new(R); R^.Info:=s; write('Dati descendentul sting al nodului ', s, ':'); R^.St:=Arb; write('Dati descendentul drept al nodului ', s, ':'); R^.Dr:=Arb; Arb:=R; end; end; {Arb }
procedure AfisArb(T : Arbore; nivel : integer); {afisarea arborelui binar } var i : integer; begin if T<>nil then begin AfisArb(T^.St, nivel+1); for i:=1 to nivel do write(' '); writeln(T^.Info); AfisArb(T^.Dr, nivel+1); end; end; {AfisareArb } Function inaltime(T : Arbore; nivel : integer):integer; var i : integer; k:integer; begin k:=0; for i:=1 to nivel do k:=k+1; inaltime:=k; end;
begin writeln('Dati radacina:'); T:=Arb; AfisArb(T, 0); readln; s:=inaltime; writeln('inaltimea este:',s); end.