Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Node:
- def __init__(self, x):
- self.key = x
- self.left = None
- self.right = None
- def insert(tree, x):
- if tree is None:
- return Node(x)
- if x < tree.key:
- tree.left = insert(tree.left, x)
- elif x > tree.key:
- tree.right = insert(tree.right, x)
- return tree
- def height(tree):
- if tree is None:
- return 0
- return max(height(tree.left), height(tree.right)) + 1
- def go(tree):
- if tree is None:
- return
- go(tree.left)
- print(tree.key, end=' ')
- go(tree.right)
- def traverse(tree):
- go(tree)
- print()
- a = list(map(int, input().split()))[:-1]
- tree = None
- for i in a:
- tree = insert(tree, i)
- # traverse(tree)
- print(height(tree))
Advertisement
Add Comment
Please, Sign In to add comment