\begin{algorithm}
\caption{Partial Sum Update Algorithm}\label{alg:usline}
\begin{algorithmic}[1]
\State $\mathcal{N}^*\gets$ bitreverse$(\mathcal{N})$
\If{$i(s)=0$}\Comment{The $s^{th}$ LSB in the binary representation of i is $0$.}
\If{$s=\log _2N - 1$ or$ i_{(\log _{2}N - 1):(s+1)} = \mathcal{N}_{(\log _{2}N - 2):s}^*$
\Endif
\Endif
\end{algorithmic}
\end{algorithm}
以上產生了「失控的爭論」。有什麼想法嗎?
答案1
最後一個缺少右大括號\If
(第一個左大括號不平衡);在下面的程式碼中我添加了它:
\documentclass{article}
\usepackage{algorithm,algpseudocode}
\begin{document}
\begin{algorithm}
\caption{Partial Sum Update Algorithm}\label{alg:usline}
\begin{algorithmic}[1]
\State $\mathcal{N}^*\gets$ bitreverse$(\mathcal{N})$
\If{$i(s)=0$}\Comment{The $s^{th}$ LSB in the binary representation of i is $0$.}
\If{$s=\log _2N - 1$ or $ i_{(\log _{2}N - 1):(s+1)} = \mathcal{N}_{(\log _{2}N - 2):s}^*}$
\EndIf
\EndIf
\end{algorithmic}
\end{algorithm}
\end{document}
另請注意,正確的語法是\EndIf
和不是\Endif
(至少如果algpseudocode
正在使用)。