二叉树节点类 发表于 2018-08-06 | 更新于 2020-06-02 | 分类于 Algorithm 二叉树节点类12345678910111213141516171819202122232425262728293031323334353637383940414243444546class Node(): def __init__(self, value=None, root_node=None, left_node=None, right_node=None): self.value = value self.root = root_node self.left = left_node self.right = right_node def set(self, value=None, root_node=None, left_node=None, right_node=None): if value is not None: self.value = value if root is not None: self.root = root_node if left is not None: self.left = left_node if right is not None: self.right = right_node def get_root(self): return self.root def get_left_node(self): return self.left def get_right_node(self): return self.right def is_leaf_node(self): if self.left is None and self.left is None: return True return False def is_root_node(self): if self.root is None: return True return False root = Node(5)left = Node(3, root)right = Node(6, root)root.set(left_node=left, right_node=right)print(root.value)print(root.root)print(root.left.value)print(root.right.value)print(root.is_leaf_node())print(root.is_root_node()) 5 None 3 6 False True 12