[Tex/LaTex] Problems with algoritmicx package

algorithmserrors

However I turn and twist it, for some reason I can't get the two lines I have commented out to work. It keeps giving me the error: "Undefined control sequence."

\begin{algorithm} 
\caption{RIGHT-ROTATE algorithm}\label{right} 
\begin{algorithmic}[1]
\Procedure{Right-Rotate}{$T,y$}\Comment{right rotation of an binary search tree}
\State{$x = y.left$}
\If{$y.right \neq T.nil$}
\State{$y.right.p = x$}
\State{$x.p = y.p$}
\EndIf
\If{$y.p == T.nil$}
\State{$T.root = x$}
%\ElseIf{$y == y.p.right$}
%\State{$y.p.right = x$}
\Else \,{$y.p.left = x$}
\EndIf
\EndProcedure 
\end{algorithmic} 
\end{algorithm}

Best Answer

It’s \ElsIf, not \ElseIf (note the missing e).

Furthermore, algorithm pseudocode can (and should, for readability) be indented as usual in LaTeX:

\If{$y.p == T.nil$}
    \State{$T.root = x$}
\ElsIf{$y == y.p.right$}
    \State{$y.p.right = x$}
\Else
    \,{$y.p.left = x$}
\EndIf