// The sequential stack is implemented. It is the # include <iostream> using namespace STD; typedef int elmtype in the data structure textbook; // # define stacksize 100 # define selemtype int # define stack_init_size 100 # define true 1 # define flase 0 # define OK 1 # define error 0 // # define overflow-2 # define infeasible -1 # define staceincrement 10 typedef int status; typedef struct {selemtype * base; selemtype * Top; int stacksize;} sqstack; int initstack (sqstack & S) {S. base = N EW elmtype [stack_init_size]; If (! S. base) Exit (overflow); S. top = S. base; return 1 ;}int gettop (sqstack S, selemtype & E) {If (S. top = S. top) Return Error; E = * (S. top-1); Return OK;} int push (sqstack & S, selemtype e) {/* If (S. top-s.base> = S. stacksize) {S. base = (selemtype *) realloc (S. base, (S. stacksize + staceincrement) * sizeof (selemtype); If (! S. base) Exit (overflow); S. top = S. base + S. stacksize; S. stacksize + = staceincrement;} */* s. top = E; S. top ++; Return e;} int POP (sqstack & S) {If (S. base = S. top) Return Error; int e = * (S. top-1); S. top = S. top-1; Return e;} int main () {sqstack s; initstack (s); push (s, 3); cout <"hello" <Endl; cout <POP (s );}
Sequence stack (1) Textbooks