Stack< T > Class Template Reference

#include <stack.h>

List of all members.

Public Member Functions

 Stack ()
 Stack (const Stack &) throw ( bad_alloc )
 ~Stack ()
bool empty () const
unsigned size () const
void clear ()
void push (const T &) throw ( bad_alloc )
pop () throw ( StackEmpty )
T & top () const throw ( StackEmpty )
const Stack< T > & operator= (const Stack< T > &) throw ( bad_alloc )


Detailed Description

template<typename T>
class Stack< T >

Implements a stack. Uses a dynamically-allocated, singly-linked list of Node<T> objects.

Author:
Mark Maloof
Version:
1.0, 28 August 2007


Constructor & Destructor Documentation

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

Default constructor.

template<typename T>
Stack< T >::Stack ( const Stack< T > &  s  )  throw ( bad_alloc )

Copy constructor.

Parameters:
s the stack to be copied
Exceptions:
bad_alloc if memory for the new stack cannot be allocated

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

Destructor.


Member Function Documentation

template<typename T>
bool Stack< T >::empty (  )  const

Returns true if this stack is empty; otherwise, returns false.

Returns:
a bool indicating whether the stack is empty

template<typename T>
unsigned Stack< T >::size (  )  const

Returns the number of items in the stack.

Returns:
an unsigned int indicating the number of items

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

Clears the stack by deleting each item.

template<typename T>
void Stack< T >::push ( const T &  item  )  throw ( bad_alloc )

Pushes the item onto this stack.

Parameters:
item the item to be added to the top of this stack
Exceptions:
bad_alloc if memory for the new item cannot be allocated

template<typename T>
T Stack< T >::pop (  )  throw ( StackEmpty )

Pops (i.e., removes) the item on the top of the stack.

Returns:
the item on top of the stack
Exceptions:
StackEmpty if the stack is empty

template<typename T>
T & Stack< T >::top (  )  const throw ( StackEmpty )

Returns a reference to the item on the top of the stack.

Returns:
a reference to the item on top of the stack
Exceptions:
StackEmpty if the stack is empty

template<typename T>
const Stack< T > & Stack< T >::operator= ( const Stack< T > &  s  )  throw ( bad_alloc )

Overloads the memberwise copy operator. Returns a reference to the copied stack for cascaded assignments (i.e., s1 = s2 = s3).

Parameters:
s the stack to be copied
Returns:
a reference to the copied stack
Exceptions:
bad_alloc if memory for the new stack cannot be allocated


The documentation for this class was generated from the following file:
Generated on Wed Sep 12 10:34:23 2007 by  doxygen 1.5.1