What the title says.

asked 01 May '12, 12:36

TSK's gravatar image

TSK
3315
accept rate: 0%

edited 01 May '12, 12:37

Sebastian%20Paaske%20T%C3%B8rholm's gravatar image

Sebastian Pa... ♦♦
86531133


The book uses this package.

link

answered 01 May '12, 13:14

kreds's gravatar image

kreds
1112
accept rate: 50%

I use algorithm2e to format my pseudocode. It doesn't give exactly the same look as you get in CLRS, but it's quite flexible, is pretty easy to use and gives a nice output.

Here's an example of it in use:

% In preamble
\usepackage[vlined, ruled, linesnumbered]{algorithm2e}
% ...
\begin{document}
% ...
\begin{algorithm}[H]
    \caption{\FuncSty{StoogeSort(}$A$,\ $i$,\ $j$\FuncSty{)}}

    \SetKwFunction{StoogeSort}{StoogeSort}
    \SetKwFunction{Swap}{Swap}

    \SetKwData{OneThird}{OneThird}
    \SetKwData{TwoThirds}{TwoThirds}

    \SetArgSty{}

    \If{$j-i \leq 1$}{ \Return{}\; }

    \OneThird  $\leftarrow i +  \frac{j-i}{3}$\;
    \TwoThirds $\leftarrow i + 2\frac{j-i}{3}$\;

    \tcc{Sort the first and last elements.}
    \If{$A[i] > A[j]$}{ \Swap{$A$, $i$, $j$}\; }

    \tcc{Then recursively sort the first 2/3rds, the last 2/3rds and the first 2/3rds again.}
    \StoogeSort{$A$, $i$, \TwoThirds}\;
    \StoogeSort{$A$, \OneThird, $j$}\;
    \StoogeSort{$A$, $i$, \TwoThirds}\;
\end{algorithm}
% ...
\end{document}

Which gives this output (tex source).

Rendered output

More examples and documentation is available in the algorithm2e manual.

link

answered 01 May '12, 12:52

Sebastian%20Paaske%20T%C3%B8rholm's gravatar image

Sebastian Pa... ♦♦
86531133
accept rate: 41%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×122
×12
×3
×1
×1

Asked: 01 May '12, 12:36

Seen: 1,332 times

Last updated: 01 May '12, 13:14

powered by OSQA