summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/thuthesis/data/chap02.tex
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/thuthesis/data/chap02.tex')
-rw-r--r--macros/latex/contrib/thuthesis/data/chap02.tex48
1 files changed, 38 insertions, 10 deletions
diff --git a/macros/latex/contrib/thuthesis/data/chap02.tex b/macros/latex/contrib/thuthesis/data/chap02.tex
index 8d6c2b070e..d084a3ccc2 100644
--- a/macros/latex/contrib/thuthesis/data/chap02.tex
+++ b/macros/latex/contrib/thuthesis/data/chap02.tex
@@ -140,14 +140,42 @@
Row 38 & & & \\
Row 39 & & & \\
Row 40 & & & \\
- Row 41 & & & \\
- Row 42 & & & \\
- Row 43 & & & \\
- Row 44 & & & \\
- Row 45 & & & \\
- Row 46 & & & \\
- Row 47 & & & \\
- Row 48 & & & \\
- Row 49 & & & \\
- Row 50 & & & \\
\end{longtable}
+
+
+
+\section{算法}
+
+算法环境可以使用 \pkg{algorithms} 或者 \pkg{algorithm2e} 宏包。
+
+\renewcommand{\algorithmicrequire}{\textbf{输入:}\unskip}
+\renewcommand{\algorithmicensure}{\textbf{输出:}\unskip}
+
+\begin{algorithm}
+ \caption{Calculate $y = x^n$}
+ \label{alg1}
+ \small
+ \begin{algorithmic}
+ \REQUIRE $n \geq 0 \vee x \neq 0$
+ \ENSURE $y = x^n$
+
+ \STATE $y \leftarrow 1$
+ \IF{$n < 0$}
+ \STATE $X \leftarrow 1 / x$
+ \STATE $N \leftarrow -n$
+ \ELSE
+ \STATE $X \leftarrow x$
+ \STATE $N \leftarrow n$
+ \ENDIF
+
+ \WHILE{$N \neq 0$}
+ \IF{$N$ is even}
+ \STATE $X \leftarrow X \times X$
+ \STATE $N \leftarrow N / 2$
+ \ELSE[$N$ is odd]
+ \STATE $y \leftarrow y \times X$
+ \STATE $N \leftarrow N - 1$
+ \ENDIF
+ \ENDWHILE
+ \end{algorithmic}
+\end{algorithm}