NAME

OTC_Stack - Implements a LIFO or stack.

SYNOPSIS


#include <OTC/collctn/stack.hh>

template<class T>
class OTC_Stack
{
  public:
    static os_typespec* get_os_typespec();
    inline ~OTC_Stack();
    OTC_Stack();
    OTC_Stack(OTC_Stack<T> const& theStack);
    OTC_Stack<T>& operator=(OTC_Stack<T> const& theStack);
    inline OTC_Boolean isEmpty() const;
    inline u_int count() const;
    inline T& top();
    inline T const& top() const;
    void push(T const& theItem);
    T pop();
    inline void clear();
    void discard(u_int theCount);
};

CLASS TYPE

Concrete

DESCRIPTION

OTC_Stack implements a LIFO or stack. Note, that it is the user's responsibility to deal with deletion of objects held in the stack, when it is parameterised over a pointer type; ie., this class works independently of the OTC_BaseActions class.

INITIALISATION

OTC_Stack();
OTC_Stack(OTC_Stack<T> const& theStack);

ASSIGNMENT

OTC_Stack<T>& operator=(OTC_Stack<T> const& theStack);

QUERY

inline OTC_Boolean isEmpty() const;
inline u_int count() const;
inline T& top();
inline T const& top() const;

MODIFICATION

void push(T const& theItem);
T pop();
inline void clear();
void discard(u_int theCount);

NOTES

To allow any number of items to be placed into the stack, it is implemented using a linked list. If efficiency is a concern, both in terms of speed and memory use, and there is a fixed upper bound on the number of items to be held, the class OTC_BoundedStack may be more appropriate.

SEE ALSO

OTC_BoundedStack

LIBRARY

OTC

AUTHOR(S)

Graham Dumpleton

COPYRIGHT

Copyright 1992 1993 OTC LIMITED
Copyright 1994 DUMPLETON SOFTWARE CONSULTING PTY LIMITED