""""
Given a binary search tree and a node in it, find the in-order successor of that node in the BST.

Note: If the given node has no in-order successor in the tree, return null.
"""


from implementations.tree import BinarySearchTree


def in_order_successor(root, el):
    succ = None
    while root:
        if root.value > el:
            succ = root
            root = root.left
        else:
            root = root.right

    return succ


if __name__ == '__main__':
    bst = BinarySearchTree.from_array([1, 4, 5, 7, 8, 9, 10])
    print in_order_successor(bst.root, 5)
