RWTStack(3C++)

RWTStack<T,C> - Rogue Wave library class

Showing IRIX 6.5.15. Unchanged since IRIX 6.5.

Name
     RWTStack<T,C> - Rogue Wave library class

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:
          well-defined copy semantics (T::T(const T&) or equiv.);

          well-defined assignment semantics (T::operator=(const T&) or
          equiv.);

          any other semantics required by class C.


Persistence
     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.  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

Public Member Functions
     1



              void
          clear();


     Removes all items from the stack.

              size_t
          entries() const;


     Returns the number of items currently on the stack.

              RWBoolean
          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 TOOL_INDEX will occur.

              T
          top() const;


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