标签:
书上的
1 #include <iostream> 2 using namespace std; 3 #define stacksize 10 4 typedef struct /*顺序栈*/ 5 { 6 int stack[stacksize]; 7 int top; /*栈顶指针*/ 8 }seqstack; 9 void initstack(seqstack *s) 10 { 11 s->top=-1; 12 } 13 int isempty(seqstack *s) 14 { 15 if(s->top==-1) 16 return 1; 17 return 0; 18 } 19 int Gettop(seqstack *s) 20 { 21 if(s->top==-1) 22 cout<<"空栈"<<endl; 23 else 24 cout<<s->stack[s->top]<<endl; 25 return 0; 26 } 27 int pushstack(seqstack *s,int num) 28 { 29 if(s->top>=stacksize-1) 30 cout<<"栈满"<<endl; 31 else 32 { 33 s->top++; 34 s->stack[s->top]=num; 35 } 36 } 37 void popstack(seqstack *s) 38 { 39 if(s->top==-1) 40 cout<<"空栈"<<endl; 41 else 42 s->top--; 43 } 44 void destroystack(seqstack *s) 45 { 46 s->top=0; 47 } 48 int main() 49 { 50 seqstack s; 51 initstack(&s); 52 pushstack(&s,1); 53 pushstack(&s,2); 54 Gettop(&s); 55 popstack(&s); 56 Gettop(&s); 57 return 0; 58 }
标签:
原文地址:http://www.cnblogs.com/a1225234/p/4664649.html