Ejemplo n.º 1
0
 def _get_helper(self, key, node: TreeNode) -> TreeNode:
     output = None
     if node.get_key() == key:
         output = node
     elif node.get_key() > key and node.get_left_child():
         output = self._get_helper(key, node.get_left_child())
     elif node.get_key() < key and node.get_right_child():
         output = self._get_helper(key, node.get_right_child())
     elif not node:
         raise KeyError
     return output
Ejemplo n.º 2
0
 def _put_helper(self, key, value, node: TreeNode) -> None:
     if key < node.get_key():
         if node.get_left_child():
             self._put_helper(key, value, node.get_left_child())
         else:
             node.set_left_child(TreeNode(key, value, parent=node))
     elif key > node.get_key():
         if node.get_right_child():
             self._put_helper(key, value, node.get_right_child())
         else:
             node.set_right_child(TreeNode(key, value, parent=node))
     else:
         node.set_value(value)