示例#1
0
def main():
    root = BinaryTreeNode(1)

    root.left = BinaryTreeNode(2)
    root.right = BinaryTreeNode(3)

    root.left.left = BinaryTreeNode(4)
    root.left.right = BinaryTreeNode(5)
    root.right.left = BinaryTreeNode(6)
    root.right.right = BinaryTreeNode(7)
    root.left.left.right = BinaryTreeNode(101)
    root.right.left.left = BinaryTreeNode(102)
    print(Tree(root))
    mirror(root)
    print(Tree(root))
示例#2
0
def main():
    root = BinaryTreeNode(1)

    root.left = BinaryTreeNode(2)
    root.right = BinaryTreeNode(3)
    print(Tree(root))
    print(get_max_path(root))
示例#3
0
def main():
    root = BinaryTreeNode(1)

    root.left = BinaryTreeNode(2)
    root.right = BinaryTreeNode(3)

    root.left.left = BinaryTreeNode(4)
    root.left.right = BinaryTreeNode(5)
    root.right.left = BinaryTreeNode(6)
    root.right.right = BinaryTreeNode(7)
    root.left.left.right = BinaryTreeNode(101)
    root.right.left.left = BinaryTreeNode(102)

    tree1 = Tree(root)

    print(tree1)
    print(tree1.size())
示例#4
0
def main():
    root = BinaryTreeNode(1)
    root.left = BinaryTreeNode(2)
    root.right = BinaryTreeNode(3)
    root2 = BinaryTreeNode(100)
    root2.left = root
    print(Tree(root2))
    print(get_max_path_leaves(root2))
def main():
    root = Node(1)

    root.left = Node(2)
    root.right = Node(3)

    root.left.left = Node(4)
    root.left.right = Node(5)
    root.right.left = Node(6)
    root.right.right = Node(7)
    root.left.left.right = Node(101)
    root.right.left.left = Node(102)

    print(Tree(root))
    arr = []
    serialize_tree(root, arr)
    print(arr)
    root, idx = deserialize_tree(arr)
    print(Tree(root))
示例#6
0
def main():
    root = BinaryTreeNode(20)
    root.left = BinaryTreeNode(10)
    root.left.left = BinaryTreeNode(5)
    root.left.left.left = BinaryTreeNode(1)
    root.left.left.left.right = BinaryTreeNode(50)
    root = BinaryTreeNode(1)
    root.left = BinaryTreeNode(3)
    root.right = BinaryTreeNode(2)
    print(Tree(root))
    print(isBST_direct(root))
示例#7
0
def main():
    root = BinaryTreeNode(1)

    root.left = BinaryTreeNode(2)
    root.right = BinaryTreeNode(3)

    root.left.left = BinaryTreeNode(4)
    root.left.right = BinaryTreeNode(5)
    root.right.left = BinaryTreeNode(6)
    root.right.right = BinaryTreeNode(7)
    root.left.left.right = BinaryTreeNode(101)
    root.right.left.left = BinaryTreeNode(102)
    print(Tree(root))
    print(get_diameter(root))
示例#8
0
def main():
    root = BinaryTreeNode(1)

    root.left = BinaryTreeNode(2)
    root.right = BinaryTreeNode(3)

    root.left.left = BinaryTreeNode(4)
    root.left.right = BinaryTreeNode(5)
    root.right.left = BinaryTreeNode(6)
    root.right.right = BinaryTreeNode(7)
    root.left.left.right = BinaryTreeNode(101)
    root.right.left.left = BinaryTreeNode(102)
    print(Tree(root))
    print(are_isomorphic(root, root))
def main():
    root = Node(1)

    root.left = Node(2)
    root.right = Node(3)

    root.left.left = Node(4)
    root.left.right = Node(5)
    root.right.left = Node(6)
    root.right.right = Node(7)
    root.left.left.right = Node(101)
    root.right.left.left = Node(102)

    print(Tree(root))
    root2 = root.left.left
    ans = is_subtree(root, root2)
    print(ans)
示例#10
0
def main():
    root = Node(1)
    root.left = Node(2)
    root.right = Node(3)
    print(Tree(root))
示例#11
0
def main():
    root = Node(1)
    root.left = Node(2)
    root.right = Node(3)
    print(Tree(root))
    print((get_lca(root, 20, 10)))