二叉搜索树的节点计数器

时间:2019-09-14 13:35:30

标签: python-3.x

我的代码无法正常工作。请告诉我,我做错了什么?谢谢您的关注!

def Count(self):
    def counter(Root):
        if self.Root is None:
            return 0
        else:
            return 1 + counter(Root.LeftChild) + counter(Root.RightChild)
    counter(self.Root)

1 个答案:

答案 0 :(得分:0)

用根替换自我。根

def Count(self):
    def counter(Root):
        if Root is None:
            return 0
        else:
            return 1 + counter(Root.LeftChild) + counter(Root.RightChild)
    counter(self.Root)
相关问题