next next up down toc toc mail

all, section 3.5.

3.5.  Use of Local Preprocessors

This example shows the Tower of Hanoi algorithm with a Nassi-Shneiderman diagram [ND] created with nsp(1). Nsp(1) converts a simple language, into Nassi-Shneiderman diagrams to be drawn by pic(1).

PostScript Version:


Tower of Hanoi

Procedure move(int n_rings, peg from, peg over, peg to):

[picture]



Troff source code:

 1      .SH
 2      Tower of Hanoi
 3      .LP
 4      Procedure move(int n_rings, peg from, peg over, peg to):
 5      .NS
 6      if if ( n_rings \(eq 1 )
 7      then    YES
 8      :       Move one ring           \
 9              from peg from\fP        \
10              to peg to\fP.
11      else    NO
12      :       move(n_rings-1, from, to, over);
13      :       move(1, from, over, to);
14      :       move(n_rings-1, over, from, to);
15      }
16      .NE
17      


back next up down toc toc mail


Created by unroff & hp-tools. © by Hans-Peter Bischof. All Rights Reserved (1998).

Last modified: 24/November/98 (09:40)