mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-02 14:56:27 -04:00
Create bst_pre_sucessor.py
This commit is contained in:
parent
2fe870650b
commit
e1a2904cfe
1 changed files with 23 additions and 0 deletions
23
trees/bst_pre_sucessor.py
Normal file
23
trees/bst_pre_sucessor.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# author: bt3gl
|
||||
|
||||
|
||||
def successor(root):
|
||||
|
||||
root = root.right
|
||||
|
||||
while root.left:
|
||||
root = root.left
|
||||
|
||||
return root
|
||||
|
||||
|
||||
def predecessor(root):
|
||||
|
||||
root = root.left
|
||||
|
||||
while root.right:
|
||||
root = root.right
|
||||
|
||||
return root
|
Loading…
Add table
Add a link
Reference in a new issue