{Checks for trees not the same shape. places numbers IN list IN an insert tree & copies it into an identical tree. THEN checks whether the first tree & second tree are identical using PROCEDURE ident.} TYPE tree = ^node; node = record info: char; left, right: tree END; VAR p, q, TreeCopy, root: tree; number: integer; same: Boolean; {\$I Tree } {Activates: BinaryTree, Intrav, MakeTree, SetLeft, and SetRight} FUNCTION copy( t:tree): tree; {copies a binary tree} VAR q,r,s: tree; BEGIN q:= NIL; IF t <> NIL THEN BEGIN r:= copy(t^.left); s:= copy(t^.right); new(q); q^.left:= r; q^.right:= s; q^.info:= t^.info; write('|', q^.info:3); END{IF}; copy:= q END{copy}; PROCEDURE ident(s, t:tree; VAR Match: boolean); {Determines whether s and t are identical trees} BEGIN IF (s = NIL) and (t <> NIL) and match THEN match := false else if (s <> NIL) and (t = NIL) and match THEN match := false else if (s <> NIL) and (t <> NIL) and match THEN BEGIN writeln('Tracing same', s^.info:3, ' tree', t^.info:3); ident(s^.left, t^.left, match); ident(s^.right, t^.right, match); IF s^.info <> t^.info THEN BEGIN writeln('Unmatching nodes are', s^.info:3, t^.info:3); match:= false END {IF s^.info} ELSE writeln('Matching nodes are', s^.info:3, t^.info:3) END {IF} END {ident}; BEGIN{main} Binary_Tree(root); writeln('Original Tree'); infix( root ); writeln; TreeCopy:=copy( root ); writeln; writeln('Copy of Tree'); infix(TreeCopy); writeln; same:= true; ident( root, TreeCopy, same); IF same THEN writeln ('The trees are identical.') ELSE writeln ('The trees are NOT identical.'); Binary_tree(q ); ident( root, q, same); IF same THEN writeln ('The trees are identical.') ELSE writeln ('The trees are NOT identical.'); END.