text cover

Data Abstraction and Problem Solving with C++

Walls and Mirrors

by Frank M. Carrano

Addison Wesley Logo

StackA.cpp

Go to the documentation of this file.
00001 
00017 #include "StackA.h"  // Stack class specification file
00018 
00019 Stack::Stack() : top(-1)
00020 {
00021 }  // end default constructor
00022 
00023 bool Stack::isEmpty() const
00024 {
00025    return top < 0;
00026 }  // end isEmpty
00027 
00028 void Stack::push(const StackItemType& newItem)
00029             throw(StackException)
00030 {
00031 // if stack has no more room for another item
00032    if (top >= MAX_STACK-1)
00033       throw StackException("StackException: stack full on push");
00034    else
00035    {  ++top;
00036       items[top] = newItem;
00037    }  // end if
00038 }  // end push
00039 
00040 void Stack::pop() throw(StackException)
00041 {
00042    if (isEmpty())
00043       throw StackException("StackException: stack empty on pop");
00044    else
00045       --top;     // stack is not empty; pop top
00046 }  // end pop
00047 
00048 void Stack::pop(StackItemType& stackTop) throw(StackException)
00049 {
00050    if (isEmpty())
00051       throw StackException("StackException: stack empty on pop");
00052    else
00053    {  // stack is not empty; retrieve top
00054       stackTop = items[top];
00055       --top;     // pop top
00056    }  // end if
00057 }  // end pop
00058 
00059 void Stack::getTop(StackItemType& stackTop) const throw(StackException)
00060 {
00061    if (isEmpty())
00062       throw StackException("StackException: stack empty on getTop");
00063    else
00064       // stack is not empty; retrieve top
00065       stackTop = items[top];
00066 }  // end getTop
00067 // End of implementation file.

Generated on Sun Aug 27 16:41:10 2006 for AWLogo by  doxygen 1.4.6