📄 stacka.cpp
字号:
// *********************************************************// Implementation file StackA.cpp for the ADT stack.// Array-based implementation.// *********************************************************#include "StackA.h" // Stack class specification fileStack::Stack(): top(-1){} // end default constructorbool Stack::isEmpty() const{ return top < 0;} // end isEmptyvoid Stack::push(StackItemType newItem) throw(StackException){// if stack has no more room for another item if (top >= MAX_STACK-1) throw StackException("StackException: stack full on push"); else { ++top; items[top] = newItem; } // end if} // end pushvoid Stack::pop() throw(StackException){ if (isEmpty()) throw StackException("StackException: stack empty on pop"); else --top; // stack is not empty; pop top} // end popvoid Stack::pop(StackItemType& stackTop) throw(StackException){ if (isEmpty()) throw StackException("StackException: stack empty on pop"); else { // stack is not empty; retrieve top stackTop = items[top]; --top; // pop top } // end if} // end popvoid Stack::getTop(StackItemType& stackTop) const throw(StackException){ if (isEmpty()) throw StackException("StackException: stack empty on getTop"); else // stack is not empty; retrieve top stackTop = items[top];} // end getTop// End of implementation file.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -