コード例 #1
0
 def find_max(self):
     """finds the value with the largest key in the tree, calls find_max function in bst.py
     Returns:
         * : the largest key in the tree
         * : the value associated with the largest key in the tree
     """
     return bst.find_max(self.tree)
コード例 #2
0
 def test_bst_find_max(self):
     t = None
     # Empty tree
     self.assertEqual(bst.find_max(t), (None, None))
     t = bst.insert(t, 2, 'two')
     # 1 Node
     self.assertEqual(bst.find_max(t), (2, 'two'))
     t = bst.insert(t, 5, 'five')
     t = bst.insert(t, 1, 'one')
     t = bst.insert(t, 0, 'zero')
     t = bst.insert(t, 3, 'three')
     t = bst.insert(t, 9, 'nine')
     t = bst.insert(t, 6, 'six')
     t = bst.insert(t, 7, 'seven')
     t = bst.insert(t, 8, 'eight')
     # Finding max in populated list
     self.assertEqual(bst.find_max(t), (9, 'nine'))
コード例 #3
0
 def find_max(self):
     """Write the docstring
     """
     #---- to do ----
     # complete this method by calling bst.find_max()
     # return the key and the value associated with the largest key in the tree
     #---------------
     key, value = bst.find_max(self.tree)
     return key, value
コード例 #4
0
ファイル: avl.py プロジェクト: nkchangliu/algorithms-1
    def delete(self, val):
        node = self.find(val)

        if node:
            lc, rc = node.left, node.right
            to_balance = find_max(
                node.left).parent if node.has_both_siblings() else node.parent

            super(AVL, self).delete(val)

            if not to_balance is None:
                to_balance.update_parent_heights()
                fix_parent_unbalance_by_rotations(to_balance)
コード例 #5
0
 def find_max(self) -> (any, any):
     """Finds the largest key in the tree by calling find_max in bst
     Returns:
         tuple (any, any): Key/value pair of the largest key in the tree
     """
     return bst.find_max(self.tree)