Stack< ElemType > Class Template Reference

#include "stack.h"

List of all members.

Public Member Functions

 Stack ()
 ~Stack ()
int size ()
bool isEmpty ()
void push (ElemType elem)
ElemType pop ()
ElemType peek ()
void clear ()


Detailed Description

template<typename ElemType>
class Stack< ElemType >

This interface defines a class template that models a "stack": that is, a linear collection of values stacked one on top of the other. Values added and removed only from the top of the stack. The fundamental stack operations are push (add to top) and pop (remove from top). A stack is said to operate in last-in-first-out (LIFO) order. For maximum generality, the Stack is supplied as a class template. The client specializes the stack to hold values of a specific type, e.g. Stack<string> or Stack<stateT>, as needed.


Constructor & Destructor Documentation

template<typename ElemType>
Stack< ElemType >::Stack (  ) 

The constructor initializes a new empty stack.

template<typename ElemType>
Stack< ElemType >::~Stack (  ) 

The destructor deallocates storage associated with this stack.


Member Function Documentation

template<typename ElemType>
int Stack< ElemType >::size (  ) 

This member function returns the number of elements in this stack.

template<typename ElemType>
bool Stack< ElemType >::isEmpty (  ) 

This member function returns true if this stack contains no elements, false otherwise.

template<typename ElemType>
void Stack< ElemType >::push ( ElemType  elem  ) 

This member function pushes the specified element onto this stack. That element becomes the top element on the stack. The stack's size increases by one.

template<typename ElemType>
ElemType Stack< ElemType >::pop (  ) 

This member function removes the top element from this stack and returns it. The top element is the one that was last pushed. The stack's size decreases by one. This function raises an error if called on an empty stack.

template<typename ElemType>
ElemType Stack< ElemType >::peek (  ) 

This member function returns the value of top element from this stack, without removing it. The stack's size is unchanged. Raises an error if peek is called on an empty stack.

template<typename ElemType>
void Stack< ElemType >::clear (  ) 

This member function removes all elements from this stack. The stack is made empty and will have size() = 0.


The documentation for this class was generated from the following file:
Generated on Mon Feb 12 23:30:08 2007 for CS 106B Libraries by  doxygen 1.5.1