MCPcopy Create free account
hub / github.com/bslatkin/effectivepython / BinaryTreeWithParent

Class BinaryTreeWithParent

example_code/item_054.py:95–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

93
94print("Example 4")
95class BinaryTreeWithParent(BinaryTree):
96 def __init__(
97 self,
98 value,
99 left=None,
100 right=None,
101 parent=None,
102 ):
103 super().__init__(value, left=left, right=right)
104 self.parent = parent
105
106 def _traverse(self, key, value):
107 if (
108 isinstance(value, BinaryTreeWithParent)
109 and key == "parent"
110 ):
111 return value.value # Prevent cycles
112 else:
113 return super()._traverse(key, value)
114
115
116print("Example 5")

Callers 1

item_054.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected