我正在编写算法,但它给出了错误。请参阅下面给出的代码:
\documentclass{beamer}
\usepackage{algorithm,algorithmic}
\begin{document}
\begin{frame}
\begin{algorithmic}
\STATE $S \Leftarrow (u,1);$
\WHILE{$S \neq \phi $}
\STATE $(u,1) \Leftarrow S ;$
\STATE color[$u$] := gray;
\IF{$k \le $ deg$(u)$};
\STATE $S \Leftarrow (u,k+1);$
\ELSE[$N$ ]
\ENDWHILE
\end{algorithmic}
\end{frame}
\end{document}
问题:如何给每一行编号?
答案1
你问,
如何给每一行编号?
由于您正在使用环境,因此如果您希望每行都编号,algorithmic
只需更改\begin{algorithmic}
为。如果仅每隔一行编号,则使用,如果仅每五行编号,则使用,等等。\begin{algorithmic}[1]
\begin{algorithmic}[2]
\begin{algorithmic}[5]
算法代码块中还存在(至少)三个语法错误:(a)缺少\ENDIF
语句,(b)缺少分支下的指令,以及(c)紧随其后的\ELSE
虚假符号。;
\IF{...}
\documentclass{beamer}
\usepackage{algorithm,algorithmic}
\begin{document}
\begin{frame}
\begin{algorithmic}[2] % number every 2nd line
\STATE $S \Leftarrow (u,1);$
\WHILE{$S \neq \phi $}
\STATE $(u,1) \Leftarrow S ;$
\STATE color[$u$] := gray;
\IF{$k \le $ deg$(u)$}
\STATE $S \Leftarrow (u,k+1);$
\ELSE[$N$]
\STATE something;
\ENDIF
\ENDWHILE
\end{algorithmic}
\end{frame}
\end{document}