Exemplo n.º 1
0
def test_traverse_empty():
    bst = BinarySearchTree()

    with pytest.raises(StopIteration):
        next(bst.traverse())
Exemplo n.º 2
0
def assert_traverse_order(item_list, bst: BinarySearchTree):
    for i, j in zip(item_list, bst.traverse()):
        assert i == j

    for i, j in zip(item_list[::-1], bst.traverse(True)):
        assert i == j
Exemplo n.º 3
0
    bst = BinarySearchTree()

    bst.add_value(5)
    bst.add_value(3)
    bst.add_value(2)
    bst.add_value(1)
    bst.add_value(20)
    bst.add_value(24)
    a = bst.add_value(25)
    bst.add_value(26)
    bst.add_value(7)
    bst.add_value(4)
    bst.add_value(6)
    bst.add_value(8)
    bst.add_value(23)
    bst.add_value(21)
    bst.add_value(22)

    print(bst.pop_min_at_parent(a))

    print(bst.pop_min())
    print(bst.pop_min())
    print(bst.pop_min())
    print(bst.pop_min())
    print(bst.pop_min())

    print('-----')

    for value in bst.traverse():
        print(value)