mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 23:11:09 +00:00
Update basic_binary_tree.py (#748)
This commit is contained in:
parent
15bc87fb41
commit
56de3df784
|
@ -4,6 +4,20 @@ class Node: # This is the Class Node with constructor that contains data variabl
|
||||||
self.left = None
|
self.left = None
|
||||||
self.right = None
|
self.right = None
|
||||||
|
|
||||||
|
def display(tree): #In Order traversal of the tree
|
||||||
|
|
||||||
|
if tree is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
if tree.left is not None:
|
||||||
|
display(tree.left)
|
||||||
|
|
||||||
|
print(tree.data)
|
||||||
|
|
||||||
|
if tree.right is not None:
|
||||||
|
display(tree.right)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
def depth_of_tree(tree): #This is the recursive function to find the depth of binary tree.
|
def depth_of_tree(tree): #This is the recursive function to find the depth of binary tree.
|
||||||
if tree is None:
|
if tree is None:
|
||||||
|
@ -41,6 +55,8 @@ def main(): # Main func for testing.
|
||||||
|
|
||||||
print(is_full_binary_tree(tree))
|
print(is_full_binary_tree(tree))
|
||||||
print(depth_of_tree(tree))
|
print(depth_of_tree(tree))
|
||||||
|
print("Tree is: ")
|
||||||
|
display(tree)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue
Block a user