31.01.2014 Views

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Stacks ( stack )<br />

1. Definition<br />

An instance S of the parameterized data type stack is a sequence of elements of data<br />

type E, called the element type of S. Insertions or deletions of elements take place only<br />

at one end of the sequence, called the top of S. <strong>The</strong> size of S is the length of the sequence,<br />

a stack of size zero is called the empty stack.<br />

2. Creation<br />

stack S;<br />

creates an instance S of type stack and initializes it to the<br />

empty stack.<br />

3. Operations<br />

E S.top( ) returns the top element of S.<br />

Precondition: S is not empty.<br />

void S.push(E x) adds x as new top element to S.<br />

E S.pop( ) deletes and returns the top element of S.<br />

Precondition: S is not empty.<br />

4. Implementation<br />

Stacks are implemented by singly linked linear lists. All operations take time O(1), except<br />

clear which takes time O(n), where n is the size of the stack.<br />

Figure C.2: <strong>The</strong> manual page for the stack data type<br />

Figure Header file of Stack shows a header file augmented by manual comments and<br />

figure A Man-Page shows the manual page produced from it. <strong>The</strong> body of a manual<br />

comment is an ordinary L A TEX-text augmented by the possiblity to quote code. Code<br />

is quoted by enclosing it either between vertical bars (|. . . |) or between double square<br />

brackets ([[. . . ]]). Code quoted by double square brackets is typeset using typewriter<br />

font and code quoted by vertical bars is given a math-like appearance. So [[S.insert(E<br />

x)]] produces S.insert(E x) and |S.insert(E x)| produces S.insert(E x).<br />

Lman is based on the command lextract. See figure ldel and lextract.<br />

lextract infile outfile [options]<br />

reads infile, processes the manual commands in it, and writes the core of a TEX-file on<br />

outfile. All Lman options apply. Lman itself works in three phases. It first produces a<br />

tempory L A TEX-file<br />

\documentclass[a4paper,size pt]{article}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!