human
4.6 Successor.
Write an algorithm to find the 'next' node of a given node in a binary search tree. You may assume that each node has a link to its parent. 
The inorder successor can be defined as the node with the smallest key greater than the key of input node. 

If right subtree of node is not null, then succ lies in the right subtree, get the minimum value in the right subtree. 

If right subtree is null, then succ is one of the ancestors. Travel up parent point until you see a node which is left child of its parent. The parent of node is succ. 

This works if all nodes have a parent pointer.
If no parent pointer

If right subtree of node is not null, then succ lies in the right subtree. Get minimum value in the right subtree
If the right subtree is null, then start from root and search. Travel down the tree, if a node's data is greater than root's data then go right, otherwise go left."
Please write code following the instructions in jupyter notebook style.
 Write me a code to 4?
assistant
#Here is code to 4.

class Node:
    def __init__(self, data):
        self.data = data
        self.left = None
        self.right = None
    
def inOrderSucc(root, n):
    if n.right is not None:
        #get minimum value in right subtree
        return minValue(n.right)
    
    p = n.parent
    #succ is parent of leftchild to parent
    while(p is not None):
        if n != p.right:
            break
        n = p
        p = p.parent
    return p 

def minValue(node):
    current = node
    
    while(current is not None):
        if current.left is None:
            break
        current = current.left
    return current