《数据结构——顺序栈的基本操作》由会员分享,可在线阅读,更多相关《数据结构——顺序栈的基本操作(4页珍藏版)》请在金锄头文库上搜索。
1、#includeusing namespace std;# define STACK_INIT_SIZE 100# define STACKINCREMENT 10typedef struct int * base;int * top;int stacksize;/当前栈可使用的最大容量 SqStack;void InitStack(SqStack &S)/构造一个空栈S.base=(int *)malloc(STACK_INIT_SIZE*sizeof(int);if(!S.base) cout=S.stacksize)S.base=(int *)realloc(S.base,(S.stac
2、ksize+STACKINCREMENT)*sizeof(int);if(!S.base) coutk;if(k=0) DestroyStack(S);n=15;if(k=1) InitStack(S);if(k=2) int a;couta;Push(S,a);DisplayStack(S);if(k=3) DisplayStack(S);if(k=4) cout栈的长度为: StackLength(S)endlendl;if(k=5) int c;GetTop(S,c);if(k=6) int b;pop(S,b);if(k=7) ClearStack(S);if(k=8) StackEmpty(S);return 0;