-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBST_Inorder.py
More file actions
48 lines (36 loc) · 838 Bytes
/
Copy pathBST_Inorder.py
File metadata and controls
48 lines (36 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'''
Note BFS == level order for proper (regular) trees
'''
class BST:
def __init__(self,val):
self.data = val
self.right = None
self.left = None
def isEmpty(root):
return root.data == []
def insert(root,node):
if root is None:
root = node
elif root.data > node.data:
if root.left is None:
root.left= node
else:
insert(root.left,node)
elif root.data < node.data:
if root.right is None:
root.right= node
else:
insert(root.right,node)
def print_inorder(root):
if not root:
return
print_inorder(root.left)
if root is not None:
print(root.data)
print_inorder(root.right)
r = BST(3)
insert(r,BST(4))
insert(r,BST(2))
insert(r,BST(5))
insert(r,BST(1))
print_inorder(r)