创建二叉树数据结构[Python]时出现问题

2024-10-01 17:26:49 发布

您现在位置:Python中文网/ 问答频道 /正文

这就是我目前所拥有的。我很困惑,我在这里错过了什么?这是标准做法吗节点左=节点(5)?我觉得很困惑。我应该在树类中有一个addLeft函数来为我做这个吗?对标准树实现有点困惑。你知道吗

class Node:
    def __init__(self,val):
        self.val = val
        self.right = None
        self.left = None

class Tree:
    def __init__(self):
        self.root = None


t = Tree()
t.root = (Node(3))


print t.root.val

Tags: 函数selfrightnonenodetree标准节点

热门问题