# Include <iostream> Using Namespace STD; Struct Tnode {tnode * Leftchild; tnode * Rightchild; Char Data ;}; tnode * Createtree () {tnode * Proot =NULL; Char Data = 0 ; CIN > Data; If (Data = ' # ' ) {Proot = NULL ;} Else {Proot = (Tnode *) malloc ( Sizeof (Tnode); proot -> DATA = Data; proot -> Leftchild = Createtree (); proot -> Rightchild = Createtree ();} Return Proot ;} Int Istreeequal (tnode * root1, tnode * Root2 ){ Bool Istree1null = (root1 = Null ); Bool Istree2null = (root2 = Null ); If (Istree1null! = Istree2null)// Two nodes { Return 0 ;} If (Istree2null & istree1null) // Both trees are empty and equal. { Return 1 ;} If (Root1-> data! = Root2-> Data ){ Return 0 ;} Return (Istreeequal (root1 -> Leftchild, root2-> leftchild )& Istreeequal (root1 -> Rightchild, root2-> Rightchild )) | (Istreeequal (root1 -> Leftchild, root2-> rightchild )& Istreeequal (root1 -> Rightchild, root2-> Leftchild ));} Void Main () {tnode * Root1 = Createtree (); tnode * Root2 = Createtree (); cout < Istreeequal (root1, root2 );}
Determine whether two binary trees are equal