📄 c06p293.txt
字号:
// *********************************************************// Header file StackA.h for the ADT stack.// Array-based implementation.// *********************************************************#include "StackException.h"const int MAX_STACK = maximum-size-of-stack;typedef desired-type-of-stack-item StackItemType;class Stack{public:// constructors and destructor: Stack(); // default constructor // copy constructor and destructor are // supplied by the compiler// stack operations: bool isEmpty() const; // Determines whether a stack is empty. // Precondition: None. // Postcondition: Returns true if the stack is empty; // otherwise returns false. void push(StackItemType newItem) throw(StackException); // Adds an item to the top of a stack. // Precondition: newItem is the item to be added. // Postcondition: If the insertion is successful, newItem // is on the top of the stack. // Exception: Throws StackException if the item cannot // be placed on the stack. void pop() throw(StackException); // Removes the top of a stack. // Precondition: None. // Postcondition: If the stack is not empty, the item // that was added most recently is removed. However, if // the stack is empty, deletion is impossible. // Exception: Throws StackException if the stack is empty. void pop(StackItemType& stackTop) throw(StackException); // Retrieves and removes the top of a stack. // Precondition: None. // Postcondition: If the stack is not empty, stackTop // contains the item that was added most recently and the // item is removed. However, if the stack is empty, // deletion is impossible and stackTop is unchanged. // Exception: Throws StackException if the stack is empty. void getTop(StackItemType& stackTop) const throw(StackException); // Retrieves the top of a stack. // Precondition: None. // Postcondition: If the stack is not empty, stackTop // contains the item that was added most recently. // However, if the stack is empty, the operation fails // and stackTop is unchanged. The stack is unchanged. // Exception: Throws StackException if the stack is empty.private: StackItemType items[MAX_STACK]; // array of stack items int top; // index to top of stack}; // end class// End of header file.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -