# Include <iostream> # include <cstring> # include <cstdlib> # define maxsize 1000 using namespace STD; // ordered structure typedef struct {int data [maxsize]; int top ;} sqstack; // initialize the stack void initstack (sqstack * & S) {S = new sqstack; s-> Top =-1; // empty stack} void clearstack (sqstack * & S) {Delete s;} // calculate the stack length int stacklength (sqstack * s) {return (S-> top + 1);} // judge whether the stack is empty int stackempty (sqstack * s) {return (S-> Top =-1 );} // int push (sqstack * & S, int e) {If (S-> Top = maxsize-1) // when the stack is full, stack Overflow return 0; s-> top ++; s-> data [S-> top] = E; // insert e into Stack top return 1 ;} // out-of-stack int POP (sqstack * & S, int e) {If (S-> Top =-1) // In the case of empty stacks, the off-Stack Overflow return 0; E = s-> data [S-> top]; S-> top --; return 1 ;}
Stack sequential storage and basic implementation