rwlogo
SourcePro 11.1

SourcePro® C++ API Reference Guide



   SourcePro C++
Documentation Home

RWTStack< T, C > Class Template Reference
[Traditional Collections]

Maintains a stack of values. More...

#include <rw/tstack.h>

List of all members.

Public Member Functions

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

Detailed Description

template<class T, class C>
class RWTStack< T, C >

Class RWTStack 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. Class T must have:

Parameter C represents the class used for implementation. Useful choices are RWTValOrderedVector<T,A> or RWTValDlist<T,A>. Class RWTValSlist<T,A> 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.

Synopsis

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

Persistence

None

Examples

 #include <iostream>
 #include <rw/tstack.h>
 #include <rw/tvordvec.h>
 
 int main()
 {
     RWTStack<int, RWTValOrderedVector<int> > stack;
 
     stack.push(1);
     stack.push(5);
     stack.push(6);
 
     while (!stack.isEmpty())
         std::cout << stack.pop() << "\n";
 
     return 0;
 }

Program output:

 6
 5
 1

Member Function Documentation

template<class T, class C>
void RWTStack< T, C >::clear ( void   )  [inline]

Removes all items from the stack.

template<class T, class C>
size_t RWTStack< T, C >::entries ( void   )  const [inline]

Returns the number of items currently on the stack.

template<class T, class C>
bool RWTStack< T, C >::isEmpty (  )  const [inline]

Returns true if there are currently no items on the stack, otherwise false.

template<class T, class C>
T RWTStack< T, C >::pop (  )  [inline]

Pops (removes and returns) the item at the top of the stack.

Exceptions:
RWBoundsErr Thrown if there are no items on the stack.
template<class T, class C>
void RWTStack< T, C >::push ( a  )  [inline]

Pushes the item a onto the top of the stack.

template<class T, class C>
T RWTStack< T, C >::top (  )  const [inline]

Returns (but does not remove) the item at the top of the stack.


© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.