Oliver Hofmann 78d4b25bd4 Renamed directories to use them as modules
Literal: Allowed compare with None
2025-04-22 19:36:59 +02:00

25 lines
731 B
Python

from utils.memory_cell import MemoryCell
class BinaryTreeNode(MemoryCell):
def __init__(self, value):
super().__init__(value)
self.left = None
self.right = None
def height(self):
left_height = self.left.height() if self.left else 0
right_height = self.right.height() if self.right else 0
return 1 + max(left_height, right_height)
def __repr__(self):
return f"TreeNode(value={self.value}, left={self.left}, right={self.right})"
def __str__(self):
return str(self.value)
def gv_rep(self, row, col):
"""Returns the graphviz representation of the node."""
return f"{id(self)} [label=\"{self.value}\", pos=\"{col},{-row}!\"];\n"