altura.pas
{ ppc386 -va -vh *.pas }
{ COMIENZO DE DESCRIPCION
Dado un \'arbol calcular su altura.
FIN DE DESCRIPCION }
{-----+-----+-----+-----+-----+-----+-----+-----+-----+-----}
{ $ Id: altura.pas 2002/04/25 9:00 mstorti Exp jdelia $ }
program p_altura;
uses u_arbori;
type
bosque = bosque_arbori;
{-----+-----+-----+-----+-----+-----+-----+-----+-----+-----}
function ALTURA (A : bosque;
n : curs_nodo) : integer;
var
c : curs_nodo;
p : integer;
h : integer ;
begin
h := -1 ;
ALTURA := h;
if (n = lambda) then exit;
c := A.HIJO_MAS_IZQ (n);
while (c <> Lambda) do begin
p := ALTURA (A, c);
if (p > h) then h := p;
c := A.HERMANO_DER (c);
end; {while}
ALTURA := h + 1;
end;
{-----+-----+-----+-----+-----+-----+-----+-----+-----+-----}
var
A : bosque;
c_arb : array [1..100] of curs_nodo;
T1, T2 : curs_nodo;
i : integer;
begin
A.INICIALIZA_NODOS;
c_arb[1] := A.CREA0 (33);
c_arb[2] := A.CREA0 (8);
c_arb[3] := A.CREA0 (7);
c_arb[4] := A.CREA0 (63);
c_arb[5] := A.CREA0 (130);
c_arb[6] := A.CREA0 (12);
c_arb[7] := A.CREA3 (41, c_arb [2], c_arb [3], c_arb [4]);
c_arb[8] := A.CREA2 (63, c_arb [1], c_arb [7]);
c_arb[9] := A.CREA0 (48);
c_arb[10] := A.CREA2 (125, c_arb [5], c_arb [6]);
T1 := A.CREA3 (142, c_arb [8], c_arb [9], c_arb [10]);
T2 := c_arb [7]; {Subarbol de T1}
writeln;
for i:=1 to 10 do begin
writeln (' subarbol c_arb [',i:2,'] ',
' etiqueta = ', A.ETIQUETA (c_arb [i]):4,
' altura = ', ALTURA ( A, c_arb [i]):4 );
end; {i}
writeln (' altura del arbol T1 : ', ALTURA (A,T1) );
writeln (' altura del arbol T2 : ', ALTURA (A,T2) );
writeln (' altura del arbol Lambda: ', ALTURA (A,Lambda));
writeln;
end.
{-----+-----+-----+-----+-----+-----+-----+-----+-----+-----}
Generated by GNU enscript 1.6.1.