stackl.cpp

来自「Data Abstraction & Problem Solving with 」· C++ 代码 · 共 73 行

CPP
73
字号
// *********************************************************// Implementation file StackL.cpp for the ADT stack.// ADT list implementation.// *********************************************************#include "StackL.h"    // header fileStack::Stack(){}  // end default constructorStack::Stack(const Stack& aStack): aList(aStack.aList){}  // end copy constructorStack::~Stack(){}  // end destructorbool Stack::isEmpty() const{   return aList.isEmpty();}  // end isEmptyvoid Stack::push(StackItemType newItem) throw(StackException){   try   {      aList.insert(1, newItem);   } // end try   catch (ListException e)   {      throw StackException("StackException: cannot push item");   } // end catch}  // end pushvoid Stack::pop() throw(StackException){   try   {      aList.remove(1);   } // end try   catch (ListIndexOutOfRangeException e)   {      throw StackException("StackException: stack empty on pop");   } // end catch}  // end popvoid Stack::pop(StackItemType& stackTop) throw(StackException){   try   {      aList.retrieve(1, stackTop);      aList.remove(1);   } // end try   catch (ListIndexOutOfRangeException e)   {      throw StackException("StackException: stack empty on pop");   } // end catch}  // end popvoid Stack::getTop(StackItemType& stackTop) const throw(StackException){   try   {      aList.retrieve(1, stackTop);   } // end try   catch (ListIndexOutOfRangeException e)   {      throw StackException("StackException: stack empty on getTop");   } // end catch}  // end getTop// End of implementation file.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?