Project 2
Public Member Functions | List of all members
Stack< ItemType > Class Template Reference

Public Member Functions

 Stack ()
 
int size () const
 
bool isEmpty () const
 
bool push (const ItemType &newItem)
 
bool pop ()
 
ItemType peek () const throw (logic_error)
 
void clear ()
 
virtual ~Stack ()
 

Constructor & Destructor Documentation

◆ Stack()

template<class ItemType >
Stack< ItemType >::Stack ( )

Stack constructor

◆ ~Stack()

template<class ItemType >
Stack< ItemType >::~Stack ( )
virtual

Stack destructor. Must delete any allocated memory.

Member Function Documentation

◆ clear()

template<class ItemType >
void Stack< ItemType >::clear ( )

Deletes all entries on the stack.

Postcondition
Stack contains no items, and the size of the stack is 0.

◆ isEmpty()

template<class ItemType >
bool Stack< ItemType >::isEmpty ( ) const

Determines whether this stack is empty.

Returns
True if the stack has no items, or false if not.

◆ peek()

template<class ItemType >
ItemType Stack< ItemType >::peek ( ) const
throw (logic_error
)

Returns the top item off of the stack without removing it. The stack size stays the same.

Returns
Item of ItemType that was on the top of the stack. Throws an exception of type logic_error if the stack is empty.

◆ pop()

template<class ItemType >
bool Stack< ItemType >::pop ( )

Pops the top item off of the stack. The stack size is decreased by 1.

Returns
True if successful, or false otherwise.

◆ push()

template<class ItemType>
bool Stack< ItemType >::push ( const ItemType &  newItem)

Pushes a new entry onto the top of the stack.

Postcondition
If successful, newItem is on the top of the stack.
Parameters
newItemThe item (of datatype ItemType) to be pushed on top of the stack.
Returns
True if insert was successful, or false if not.

◆ size()

template<class ItemType >
int Stack< ItemType >::size ( ) const

Returns the number of items on the stack.

Returns
The integer number of items on the stack.

The documentation for this class was generated from the following files: