两棵二叉树相等是指两棵二叉树有着相同的结构,并且在相同位置的节点有相同的值。
class Btree():
def __init(self):
self.data=None
self.lchild=None
self.rchild=None
def isequal(t1,t2):
if t1!=None and t2==None:
return False
if t1==None and t2!=None:
return False
if t1==None and t2==None:
return True
if t1.data==t2.data:
return isequal(t1.lchild,t2.lchild) and isequal(t1.rchild,t2.rchild)