Files
AlgorithmNotes/Foundations/overview/nonincreasing-insertion-sort.tex
pezy_mbp c9d631140f added 2.1-1,2,3
1. added insertion-sort pseudocode and code,unittest
2. added 2.1-1 and 2.1-2
3. part of 2.1-3
2015-05-11 01:09:00 +08:00

25 lines
549 B
TeX

\documentclass{article}
\usepackage{clrscode3e}
\begin{document}
\title{2.1-2}
\author{pezy}
\maketitle
\begin{codebox}
\Procname{$\proc{Nonincreasing-Insertion-Sort}(A)$}
\li \For $j \gets 2$ \To $\attrib{A}{length}$
\li \Do
$\id{key} \gets A[j]$
\li \Comment Insert $A[j]$ into the sorted sequence $A[1 \twodots j-1]$.
\li $i \gets j-1$
\li \While $i > 0$ and $A[i] < \id{key}$
\li \Do
$A[i+1] \gets A[i]$
\li $i \gets i-1$
\End
\li $A[i+1] \gets \id{key}$
\End
\end{codebox}
\end{document}