GET Parent pointer whose right child is not a parent or itself of this node . There might be case when parent has no right child , but , current node is left child of the parent ( second condition is for that ) .
while ( node . parent . right == node or ( node . parent . right == None and node . parent . left == node ) ) : NEW_LINE INDENT if ( node . parent == None ) : NEW_LINE INDENT return None NEW_LINE DEDENT node = node . parent NEW_LINE level -= 1 NEW_LINE DEDENT