Пример #1
0
def main():
    functions = [invert_bt, invert_bt_v2]
    for f in functions:
        print(f"""{'*'*20} Running: {f.__name__} {'*'*20}""")
        L = [randrange(1, 1000) for _ in range(20)]
        bst = gen_bst(L)
        print("Before Invertion:", bst, sep='\n')
        f(bst)
        print("After Invertion:", bst, sep='\n')
def main():
    for _ in range(5):
        L = [randint(-5, 5) for _ in range(10)]
        bst = gen_bst(L)
        print(bst)
        returned1 = find_consecutive_length(bst)
        returned2 = find_consecutive_length_v2(bst)
        assert returned1 == returned2
        print(returned1)
def main():
    for _ in range(10):
        bst = gen_bst([randint(-20, 20) for _ in range(15)])
        nodes_count = count_full_nodes(bst)
        full_nds1 = collect_full_nodes_v1(bst)
        full_nds2 = collect_full_nodes_v2(bst)

        assert full_nds1.sort() == full_nds2.sort()

        print(bst,
              f"Number of full Nodes: {nodes_count}",
              f"Full Nodes: {full_nds1}",
              sep='\n')
def test_count_leaves(L, expected):
    bst = gen_bst(L, type=AVL)
    assert count_leaves(bst._root) == expected
def test_width_bt(L, expected):
    bst = gen_bst(L)
    assert width_bt(bst._root) == expected
def test_height_bt(L, expected):
    bst = gen_bst(L)
    assert height_bt_v1(bst._root) == expected
    assert height_bt_v2(bst._root) == expected + 1
Пример #7
0
def main():
    bst = gen_bst([randint(0, 20) for _ in range(7)])
    print(bst, preorder_rec(bst), sep='\n\n')
def main():
    bst = gen_bst([randint(0, 20) for _ in range(7)])
    print(bst, max_binary_tree(bst), sep='\n\n')
Пример #9
0
def main():
    L = [randint(-20, 20) for _ in range(20)]
    bst = gen_bst(L)
    returned = right_view_bt(bst)
    print(bst, returned, sep='\n\n')