我有这个算法:
\begin{algorithm}
\begin{algorithmic}[1]
\caption{Build-PGM-Index}
\State{levels} = array dinamico vuoto;
\State{i} = 0;
\State{keys} = A;
\Repeat
\State{$M$} = Build-PLA-model($keys, \epsilon$);
\State{levels[i]} = $M$; \State{i} = $i + 1$;
\State{m} = $Size(M)$;
\State{keys} = $[M[0].key, \dots, M[m-1].key]$
\Until{m = 1}\\
\Return{levels rovesciato}
\end{algorithmic}
\end{algorithm}
我怎样才能将\State{i} = 0;
和写\State{keys} = A;
在同一行?
答案1
\State
不接收参数;只需使用
\State i=0; keys = A
但是你的排版不一致。需要时使用数学。
\documentclass{article}
\usepackage{amsmath}
\usepackage{algorithm,algpseudocode}
\begin{document}
\begin{algorithm}
\begin{algorithmic}[1]
\caption{Build-PGM-Index}
\State $\mathit{levels} = \text{array dinamico vuoto}$;
\State $i = 0$; $\mathit{keys} = A$;
\Repeat
\State $M = \textup{Build-PLA-model}(\mathit{keys}, \epsilon)$;
\State $\mathit{levels}[i] = M$; $i = i + 1$;
\State $m = \textup{Size}(M)$;
\State $\mathit{keys} = [M[0].\mathit{key}, \dots, M[m-1].\mathit{key}]$
\Until{$m = 1$}\\
\Return $\mathit{levels}$ rovesciato
\end{algorithmic}
\end{algorithm}
\end{document}