Module: Essential Tools Module Group: Traditional Collection Classes
Does not inherit
#include <rw/tstack.h> RWTStack<T, C> stack;
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:
well-defined copy semantics (T::T(const T&) or equivalent);
well-defined assignment semantics (T::operator=(const T&) or equivalent);
any other semantics required by class C.
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.
None
In this example a stack of ints, implemented as an ordered vector, is exercised.
#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
void clear();
Removes all items from the stack.
size_t entries() const;
Returns the number of items currently on the stack.
bool isEmpty() const;
Returns true if there are currently no items on the stack, false otherwise.
void push(T a);
Push the item a onto the top of the stack.
T pop();
Pop (remove and return) the item at the top of the stack. If there are no items on the stack then an exception of type RWBoundsErr will occur.
T top() const;
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.