-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmaximum_num_inTree.py
More file actions
44 lines (29 loc) · 831 Bytes
/
maximum_num_inTree.py
File metadata and controls
44 lines (29 loc) · 831 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
class Node:
def __init__(self, data):
self.left = None
self.right = None
self.data = data
def print_tree(self):
if self.left:
self.left.print_tree()
print(self.data),
if self.right:
self.right.print_tree()
def max_num(node):
current = node
if current:
while current.right is not None:
print("current.right:", current.right.data)
current = current.right
print("current", current.data)
return current.data
root = Node(12)
root.left = Node(11)
root.left.left = Node(10)
root.left.left.left = Node(13)
root.left.right = Node(14)
root.right = Node(18)
root.right.right = Node(20)
root.right.left = Node(15)
root.print_tree()
print("Maximum number in tree is %d" % (max_num(root)))