If q has right child , then right child is nextRight of p and we also need to set nextRight of right child
if ( q . right ) : NEW_LINE INDENT q . left . nextRight = q . right NEW_LINE DEDENT else : NEW_LINE INDENT q . left . nextRight = getNextRight ( q ) NEW_LINE DEDENT if ( q . right ) : NEW_LINE q . right . nextRight = getNextRight ( q ) NEW_LINE