This function returns the inorder successor of a node in a BST
(root: Node)
| 2 | |
| 3 | |
| 4 | def inorder_successor(root: Node) -> Node: |
| 5 | """This function returns the inorder successor of a node in a BST""" |
| 6 | |
| 7 | # The inorder successor of a node is the node with the smallest value greater than the value of the node |
| 8 | current: Node = root |
| 9 | |
| 10 | # The inorder successor is the leftmost node in the right subtree |
| 11 | while current.left is not None: |
| 12 | current = current.left |
| 13 | return current |