Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

RWTStack<T,C>

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Synopsis

#include <rw/tstack.h>
RWTStack<T, C> stack;

Description

This class maintains a stack of values. Not only can the type of object inserted onto the stack be parameterized, but also the implementation of the stack.

Parameter T represents the type of object in the stack, either a class or built in type. The class T must have:

Parameter C represents the class used for implementation. Useful choices are RWTValOrderedVector<T> or RWTValDlist<T>. Class RWTValSlist<T> can also be used, but note that singly-linked lists are less efficient at removing the last item of a list (function pop()), because of the necessity of searching the list for the next-to-the-last item.

Persistence

None

Example

In this example a stack of ints, implemented as an ordered vector, is exercised.

#include <rw/tstack.h>
#include <rw/tvordvec.h>
#include <rw/rstream.h>

main() {
  RWTStack<int, RWTValOrderedVector<int> > stack;

  stack.push(1);
  stack.push(5);
  stack.push(6);

  while (!stack.isEmpty())
    cout << stack.pop() << endl;
  return 0;
}
 

Program output:

6
5
1

Public Member Functions

void
clear();
size_t
entries() const; 
RWBoolean
isEmpty() const; 
void
push(T a); 
T
pop();
T
top() const; 


Previous fileTop of documentContentsIndexNext file
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.