mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-06-17 11:29:27 -04:00
Create find_inorder_successor.py
This commit is contained in:
parent
3d8bf7d339
commit
abbad25ed8
1 changed files with 18 additions and 0 deletions
18
trees/find_inorder_successor.py
Normal file
18
trees/find_inorder_successor.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# author: bt3gl
|
||||||
|
|
||||||
|
|
||||||
|
def find_inorder_successor(root):
|
||||||
|
|
||||||
|
successor = None
|
||||||
|
|
||||||
|
while root:
|
||||||
|
|
||||||
|
if root.val <= p.val:
|
||||||
|
root = root.right
|
||||||
|
else:
|
||||||
|
successor = root
|
||||||
|
root = root.left
|
||||||
|
|
||||||
|
return successor
|
Loading…
Add table
Add a link
Reference in a new issue