#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;/*push (int item) int pop () Top () returns the next element in Stact s.top () = 12; Sets the top level element to return a reference to it*/Const intn=Ten;Const intan=5; intSize//Record Sizeint*stack;//Storing DataintTop//Record Top elementvoidPushintItem) { if(top==size) { int*a=New int[size+An ]; for(intI=0; i<size;i++) {A[i]=Stack[i]; } Stack=A; } stack[top++]=item;}intpop () {if(top>0) returnstack[--top];}int&Ttop () {if(top==size) { int*a=New int[size+An ]; for(intI=0; i<size;i++) {A[i]=Stack[i]; } Stack=A; } returnstack[top++];}intMain () {top=0; Stack=New int[N]; Size=N; for(intI=0;i<2*n;i++) {push (i); } cout<<"Top:"<<top<<Endl; cout<<"pop ()"<<pop () <<Endl; Ttop ()= the; for(intI=0; i<top;i++) {cout<<stack[i]<<" "; } return 0;}
My STL Tour Mystack