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.

6.5 Bounded Stacks ( b stack )<br />

1. Definition<br />

An instance S of the parameterized data type b stack is a stack (see section 6.3) of<br />

bounded size.<br />

#include < <strong>LEDA</strong>/core/b stack.h ><br />

2. Creation<br />

b stack S(int n);<br />

creates an instance S of type b stack that can hold up to n<br />

elements. S is initialized with the empty stack.<br />

3. Operations<br />

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

Precondition: S is not empty.<br />

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

Precondition: S is not empty.<br />

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

Precondition: S.size() < n.<br />

void S.clear( ) makes S the empty stack.<br />

int S.size( ) returns the size of S.<br />

bool S.empty( ) returns true if S is empty, false otherwise.<br />

4. Implementation<br />

Bounded stacks are implemented by C++vectors.<br />

space requirement is O(n).<br />

All operations take time O(1). <strong>The</strong>

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

Saved successfully!

Ooh no, something went wrong!