![]() |
Data Abstraction and Problem Solving with C++Walls and Mirrorsby Frank M. Carrano |
![]() |
StackL.cppGo to the documentation of this file.00001 00017 #include "StackL.h" // header file 00018 00019 Stack::Stack() 00020 { 00021 } // end default constructor 00022 00023 Stack::Stack(const Stack& aStack) 00024 : aList(aStack.aList) 00025 { 00026 } // end copy constructor 00027 00028 Stack::~Stack() 00029 { 00030 } // end destructor 00031 00032 bool Stack::isEmpty() const 00033 { 00034 return aList.isEmpty(); 00035 } // end isEmpty 00036 00037 void Stack::push(const StackItemType& newItem) 00038 throw(StackException) 00039 { 00040 try 00041 { 00042 aList.insert(1, newItem); 00043 } // end try 00044 catch (ListException e) 00045 { 00046 throw StackException("StackException: cannot push item."); 00047 } // end catch 00048 catch (ListIndexOutOfRangeException e) 00049 { 00050 throw StackException("StackException: cannot push item."); 00051 } // end catch 00052 } // end push 00053 00054 void Stack::pop() throw(StackException) 00055 { 00056 try 00057 { 00058 aList.remove(1); 00059 } // end try 00060 catch (ListIndexOutOfRangeException e) 00061 { 00062 throw StackException("StackException: stack empty on pop"); 00063 } // end catch 00064 } // end pop 00065 00066 void Stack::pop(StackItemType& stackTop) throw(StackException) 00067 { 00068 try 00069 { 00070 aList.retrieve(1, stackTop); 00071 aList.remove(1); 00072 } // end try 00073 catch (ListIndexOutOfRangeException e) 00074 { 00075 throw StackException("StackException: stack empty on pop"); 00076 } // end catch 00077 } // end pop 00078 00079 void Stack::getTop(StackItemType& stackTop) const throw(StackException) 00080 { 00081 try 00082 { 00083 aList.retrieve(1, stackTop); 00084 } // end try 00085 catch (ListIndexOutOfRangeException e) 00086 { 00087 throw StackException("StackException: stack empty on getTop"); 00088 } // end catch 00089 } // end getTop 00090 // End of implementation file. |