Arvorebinariacompleta

398 palavras 2 páginas
program testearv;

(* uses crt; *)

type arv = ^no; no = record esq : arv; item : integer; dir : arv; end;

var t1,t2: arv; n: integer;

procedure Insere(var t1:arv; x:integer); begin if t1=nil then begin new(t1); t1^.item:=x; t1^.esq:=nil; t1^.dir:=nil; end else if x < t1^.item then Insere(t1^.esq,x) else Insere(t1^.dir,x); end; procedure Insere1(var t2:arv; x:integer); begin if t2=nil then begin new(t2); t2^.item:=x; t2^.esq:=nil; t2^.dir:=nil; end else if x<t2^.item then Insere1(t2^.esq,x) else Insere1(t2^.dir,x); end; procedure Imprime(t1: arv); begin if t1=nil then write('') else begin Imprime(t1^.esq); write(t1^.item,' '); Imprime(t1^.dir); end; end; procedure Imprime1(t2: arv); begin if t2=nil then write('') else begin Imprime1(t2^.esq); write(t2^.item); Imprime1(t2^.dir); end; end; function Iguais(t1,t2: arv):boolean; begin if ((t1=nil) and (t2=nil)) then Iguais:=true else if ((t1=nil) or (t2=nil)) then Iguais:=false else if ((t1^.item)<>(t2^.item)) then Iguais:=false else Iguais:=Iguais((t1^.esq),(t2^.esq)) and Iguais((t1^.dir),(t2^.dir)); end; function Similar(t1,t2: arv):boolean; begin if ((t1=nil) and (t2=nil)) then Similar:=true else if ((t1=nil) or (t2=nil)) then Similar:=false else Similar:=Similar((t1^.esq),(t2^.esq)) and Similar((t1^.dir),(t2^.dir)); end; function Espelhada(t1,t2: arv):boolean; begin if ((t1=nil) and (t2=nil)) then Espelhada:=true else if ((t1=nil)or(t2=nil)) then Espelhada:=false else

Relacionados