1#include <iostream>2#include <stdlib.h>3 using namespacestd;4 5 #defineMaxSize 306 7typedefstruct8 {9 intData[maxsize];Ten inttop; One }sqstack; A - voidInitstack (Sqstack &S) - { thes.top=-1; - } - - intIsEmpty (sqstack S) + { - if(s.top==-1) + return 1; A Else at return 0; - } - - intPush (Sqstack &s,inte) - { - if(s.top==maxsize-1) in return 0; -++(s.top); tos.data[s.top]=e; + return 1; - } the * intPop (Sqstack &s,int&e) $ {Panax Notoginseng if(s.top==-1) - return 0; theE=S.data[s.top]; +--(s.top); A return 0; the } + - intGetTop (Sqstack S,int&e) $ { $ if(s.top==-1) - return 0; -E=S.data[s.top]; the--(s.top); - return 1;Wuyi } the - voidPrint (sqstack S) Wu { - if(s.top==-1) Aboutcout<<"The order stack is empty! "<<Endl; $ Else - { - while(s.top!=-1) - { Acout<<" "<<S.data[S.top--]<<" "; + } the } - } $ the intMain () the { the intI=0; the inte; - Sqstack S; in Initstack (S); the thecout<<"\ n--------------------------------\ n"; Aboutcout<<"\ n The elements in the sequential stack are: \ n"; the for(i=0;i<Ten;++i) the Push (s,i); the Print (S); + if((E=isempty (S)) = =1) -cout<<"\ n The sequential stack is empty! \ n"; the ElseBayicout<<"\ n Sequential stack is not empty! \ n"; the thecout<<"\ n--------------------------------\ n"; -cout<<"\ nthe element in the sequence stack after removing the top element of the stack is: \ n"; - Pop (s,e); the Print (S); the thecout<<"\ n--------------------------------\ n"; the GetTop (s,e); -cout<<"\ nthe top element of this stack is:"<<e<<Endl; thecout<<"\ n The elements in the sequential stack are: \ n"; the Print (S); the return 0;94}
Data structures-sequential stacks