我想创建一个函数来比较两个bst,看看它们是否相同。比较两个bsts
这是我迄今为止
def same(self,another):
same = False
for j in another:
for i in self:
if self[i] == another[j]:
same = True
return same
,我就来测试一下是这样,first.same(另一个),看看他们是相同的方式。
这是我更新的功能:
def same(self, another):
is_same = False
if self == None and another == None:
is_same = True
if self is not None and another is not None:
is_same = ((self._root == rs._root) and identical(self._left, rs._left) and identical(self._right, rs._right))
return is_another
这是我想出了,但任何事情我有了这个功能,我都会得到一个错误的测试。
你是如何移动到左侧和右侧的子树? – attaboy182
嗯,我会做到这一点,但我不完全确定如何做到这一点, –