Exemplo n.º 1
0
def test_remove_root():
    root = BinarySearchTree(4)
    root.insert(2)
    root.insert(6)
    root.insert(1)
    root.insert(3)
    root.insert(5)
    root.insert(7)
    assert list(root.levelorder()) == [4, 2, 6, 1, 3, 5, 7]
    root.remove(4)
    assert list(root.levelordernested()) == [[5], [2, 6], [1, 3, 7]]
Exemplo n.º 2
0
def test_remove_twochildren():
    root = BinarySearchTree(4)
    root.insert(2)
    root.insert(6)
    root.insert(1)
    root.insert(3)
    root.insert(5)
    root.insert(7)
    assert list(root.levelorder()) == [4, 2, 6, 1, 3, 5, 7]
    root.remove(7)
    root.remove(6)
    root.remove(2)
    assert list(root.levelordernested()) == [[4], [3, 5], [1]]