-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4.6.py
More file actions
28 lines (23 loc) · 651 Bytes
/
4.6.py
File metadata and controls
28 lines (23 loc) · 651 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
# Create Node Class:
class Node:
def __init__(self, data):
self.data = data
self.right = None
self.left = None
def next_in_order(root, in_order_list):
if root:
next_in_order(root.left, in_order_list)
in_order_list.append(root.data)
next_in_order(root.right, in_order_list)
return in_order_list
root = Node(4)
root.left = Node(3)
root.right = Node(8)
root.left.left = Node("b")
root.left.right = Node("e")
in_order_list = []
n = "e"
in_order_list = next_in_order(root, in_order_list)
for index, val in enumerate(in_order_list):
if val == n:
print(in_order_list[index + 1])