示例#1
0
def __main():
    dfs()
    preorder()
    return bfs()
    n = short_tree(list(range(15)))
    print(n)
    return
    n = short_tree(7 * [1])
    ll = list_of_depths(n)
    display(ll)
    print(30 * '=')

    print(n)
    print(num_paths(n, 2))
    pass
示例#2
0
文件: p4_5.py 项目: sweettuse/pyaoc
def __main():
    n = short_tree(list(range(15)))
    print(is_valid_bst(n))
    end = BNode(21, BNode(22))
    n.left.left.left.left = end
    print(is_valid_bst(n))
    pass
示例#3
0
def __main():
    n = short_tree(list(range(12)))
    end = BNode(20, BNode(21), BNode(22))
    # n.left.left.left.left = end
    print(is_balanced(n))
    print(_height.cache_info())
    pass
示例#4
0
def preorder():
    n = short_tree(list(range(15)))

    def _order(n):
        if not n:
            return
        yield from _order(n.left)
        yield from _order(n.right)
        yield n.v

    print(' -> '.join(map(str, _order(n))))
示例#5
0
def bfs():
    n = short_tree(list(range(15)))
    nodes = deque([n])
    res = []
    while nodes:
        cur = nodes.popleft()
        if not cur:
            continue
        res.append(cur.v)
        nodes.append(cur.left)
        nodes.append(cur.right)
    print(' -> '.join(map(str, res)))
示例#6
0
def __main():
    max_size = 2 ** 20
    with localtimer():
        n = short_tree(list(range(max_size)))
    print(find_common2(n, 1, max_size - 1))
    pass
示例#7
0
def __main():
    t = short_tree(list(range(15)))
    display(list_of_depths(t))
示例#8
0
文件: p4_9.py 项目: sweettuse/pyaoc
def __main():
    for size in range(4, 24):
        n = short_tree(list(range(1, size + 1)))
        print(size, len(possible_inputs(n)))
        if size == 11:
            print(possible_inputs(n))
示例#9
0
文件: p4_10.py 项目: sweettuse/pyaoc
def __main():
    n1 = short_tree(list(range(31)))
    n2 = short_tree(list(range(15)))
    print(n1.v, n2.v)
    print(is_subtree(n1, n2))
示例#10
0
def __main():
    n = short_tree(list(range(15)))
    for t in n:
        print(t)
    pass