不管我怎么努力,出于某种原因,我无法让注释掉的两行代码正常工作。它一直给我错误:“未定义的控制序列。”
\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}
答案1
它是\ElsIf
,而不是\ElseIf
(请注意缺失的e
)。
此外,算法伪代码可以(并且应该,为了可读性)像往常一样在 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