-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathent4a.py
36 lines (25 loc) · 849 Bytes
/
ent4a.py
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
class TreeNode:
def __init__(self, value=None, left=None, right=None, parent=None):
self.value = value
self.left = left
self.right = right
self.parent = parent
def in_order_succ(node: TreeNode) -> TreeNode:
if node is not None:
if node.right is not None:
buff = node.right
while buff.left is not None:
buff = buff.left
return buff
elif node.parent is not None:
if node.parent.value < node.value:
buff = node.parent
while buff and buff.value < node.value:
buff = buff.parent
return buff
else:
return node.parent
else:
return None
else:
return None