测试图片code
def is_full_binary_tree(tree): # This functions returns that is it full binary tree or not?
if tree is None:
return True
def main(): # Main func for testing. tree = Node(1) tree.left = Node(2) tree.right = Node(3) tree.left.left = Node(4) tree.left.right = Node(5) tree.left.right.left = Node(6) tree.right.left = Node(7) tree.right.left.left = Node(8) tree.right.left.left.right = Node(9)
print(is_full_binary_tree(tree)) print(depth_of_tree(tree)) print("Tree is: ") display(tree)
if __name__ == '__main__': main()
|
if (tree.left is None) and (tree.right is None):
return True
if (tree.left is not None) and (tree.right is not None):
return (is_full_binary_tree(tree.left) and is_full_binary_
def main(): # Main func for testing.
tree = Node(1)
tree.left = Node(2)
tree.right = Node(3)
tree.left.left = Node(4)
tree.left.right = Node(5)
tree.left.right.left = Node(6)
tree.right.left = Node(7)
tree.right.left.left = Node(8)
tree.right.left.left.right = Node(9)
print(is_full_binary_tree(tree))
print(depth_of_tree(tree))
print("Tree is: ")
display(tree)
if __name__ == '__main__':
main()