Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Node:
- def __init__(self, data):
- self.left = None
- self.right = None
- self.data = data
- def insert(self, data, depth=1):
- if self.data:
- if data <= self.data:
- if self.left is None:
- self.left = Node(data)
- print(depth+1,end=" ")
- else:
- self.left.insert(data,depth+1)
- elif data > self.data:
- if self.right is None:
- self.right = Node(data)
- print(depth+1,end=" ")
- else:
- self.right.insert(data,depth+1)
- depth+=1
- else:
- self.data = data
- print(depth,end=" ")
- ls=[]
- N=int(input())
- ls=list((map(int, input().split())))
- root=Node(ls[0])
- print(1,end=" ")
- for i in range(1,len(ls)):
- root.insert(ls[i])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement