在latex中画算法流程图

\documentclass{article}
\usepackage{amsmath}
\usepackage{algorithm}
\usepackage{algpseudocode}

\makeatletter
\def\BState{\State\hskip-\ALG@thistlm}
\makeatother

\floatname{algorithm}{Procedure}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}

\begin{document}
	\begin{algorithm}
		\caption{My algorithm}\label{euclid}
		\begin{algorithmic}[1]
			\Procedure{MyProcedure}{}
			
			
				abc
			\State $\textit{stringlen} \gets \text{length of }\textit{string}$
			\State $i \gets \textit{patlen}$
			\BState \emph{top}:
			\If {$i > \textit{stringlen}$} \Return false
			\EndIf
			\State $j \gets \textit{patlen}$
			\BState \emph{loop}:
			\If {$\textit{string}(i) = \textit{path}(j)$}
			\State $j \gets j-1$.
			\State $i \gets i-1$.
			\State \textbf{goto} \emph{loop}.
			\State \textbf{close};
			\EndIf
			\State $i \gets i+\max(\textit{delta}_1(\textit{string}(i)),\textit{delta}_2(j))$.
			\State \textbf{goto} \emph{top}.
			\EndProcedure
		\end{algorithmic}
	\end{algorithm}
	
	
	
	
	\begin{algorithm}[h]
		\caption{An example for format For \& While Loop in Algorithm}
		\begin{algorithmic}[1]
			\For{each $i\in [1,9]$}
			\State initialize a tree $T_{i}$ with only a leaf (the root);
			\State $T=T\cup T_{i};$
			\EndFor
			\ForAll {$c$ such that $c\in RecentMBatch(E_{n-1})$}
			\label{code:TrainBase:getc}
			\State $T=T\cup PosSample(c)$;
			\label{code:TrainBase:pos}
			\EndFor;
			\For{$i=1$; $i<n$; $i++$ }
			\State $//$ Your source here;
			\EndFor
			\For{$i=1$ to $n$}
			\State $//$ Your source here;
			\EndFor
			\State $//$ Reusing recent base classifiers.
			\label{code:recentStart}
			\While {$(|E_n| \leq L_1 )and( D \neq \phi)$}
			\State Selecting the most recent classifier $c_i$ from $D$;
			\State $D=D-c_i$;
			\State $E_n=E_n+c_i$;
			\EndWhile
			\label{code:recentEnd}
		\end{algorithmic}
	\end{algorithm}
\end{document} 





参考:

https://en.wikibooks.org/wiki/LaTeX/Algorithms

http://blog.sina.com.cn/s/blog_5e16f1770102ezhv.html

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值