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:
- 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. The class C
must provide the following interface (or equivalent):
void C::append(const T&)
void C::clear()
size_t C::entries() const
T C::last()
bool C::isEmpty() const
T C::removeLast()
- a default constructor (
C::C()
)
- a copy constructor (
C::C(const C&)
)
- an assignment operator (
C& C::operator=(const C&)
)
These methods must behave in a manner that is consistent with that of RWTValDlist for this class to function as intended.
Useful choices for C
are RWTValDlist or RWTValOrderedVector. Singly- linked list classes, such as RWTValSlist, can also be used, but tend to be less efficient at removing the last item.
- Synopsis
#include <rw/tstack.h>
Maintains a stack of values.
Definition tstack.h:101
- Persistence
- None
- Example
#include <rw/tstack.h>
#include <rw/tvordvec.h>
#include <iostream>
int main() {
std::cout << stack.
pop() <<
"\n";
}
return 0;
}
T pop()
Definition tstack.h:197
bool isEmpty() const
Definition tstack.h:175
void push(const T &a)
Definition tstack.h:180
Program output: