(Please see PDF link below)
def preorder( node ): print node.key preorder( node.left ) preorder( node.right )
def successor( node ): if node.right != NULL: return min( node.right ) (cur, par) = (node, node.parent) while (par != NULL) and (cur == par.right): (cur, par) = (par, par.parent) return par
def insert( root, key ): cur = root while cur != NULL: if key < cur.key: # go left if cur.left == NULL: cur.left = new Node( key ) cur.left.parent = cur return cur = cur.left else: # go right if cur.right == NULL: cur.right = new Node( key ) cur.right.parent = cur return cur = cur.right