The following Code is only used by me to review the data structure. Its practicality is low ~~ Haha:>
/// C ++ template technology to implement a Simple Sequential stack. // # include <cstdlib> # include <iostream> # include <iomanip> # include <stdexcept> // sequence stack template. // template <typename T> class Stack {PRIVATE: int _ top; size_t _ size; T * _ pstack; static const size_t _ def_size = 20; /// _ min_top should not be of the size_t type. // because the int type is converted to the size_t type when the size_t type is compared with the int type. // static const int _ mix_top = 0; public: Stack (const size_t size = _ def_size): _ top (_ mix_top-1), _ SIZE (size) {_ pstack = new T [_ SIZE] ;}~ Stack (void) {Delete [] _ pstack;} bool isempty (void) const {return _ mix_top> _ top;} bool isfull (void) const {return _ size-1 = _ top;} t gettop (void) const {If (isempty () {Throw STD: underflow_error ("Stack is empty and off! ");} Return _ pstack [_ top];} void push (const T & Val) {If (isfull () {Throw STD: overflow_error (" the stack is full! ");} _ Pstack [++ _ top] = val;} t POP (void) {If (isempty () {Throw STD: underflow_error (" Stack is empty and off! ") ;}Return _ pstack [_ top --] ;}}; // test stack. // int main (void) {const size_t max_size = 20; stack <int> stack (max_size); STD: cout <"stack" <(stack. isempty ()? "": "No") <"blank." <STD: Endl; STD: cout <"stack" <(stack. isfull ()? "": "No") <"is full. "<STD: Endl; For (size_t I = 0; I <max_size; ++ I) {stack. push (I); STD: cout <STD: SETW (3) <stack. gettop ();} // stack. push (max_size); STD: cout <STD: Endl; STD: cout <"stack" <(stack. isempty ()? "": "No") <"blank." <STD: Endl; STD: cout <"stack" <(stack. isfull ()? "": "No") <"is full. "<STD: Endl; For (size_t I = 0; I <max_size; ++ I) {STD: cout <STD: SETW (3) <stack. pop ();} // STD: cout <STD: SETW (3) <stack. pop (); Return exit_success ;}