st->data[st->top]=x; //元素进栈 } }
void Pop(SqStack *st,ElemType &e) //出栈 { if(st->top==-1) { printf(\栈下溢出\\n\ } else { e=st->data[st->top]; //元素出栈 st->top--; //移动栈顶位置 } }
void Push1(SqStack *st) //元素进栈 { int x[5]; int i; if(st->top==MaxSize-1) { printf(\栈上溢出!\\n\ } else { printf(\请输入5个元素:\ for(i=0;i<5;i++) scanf(\ for(i=4;i>=0;i--) { st->top++; //移动栈顶位置 st->data[st->top]=x[i]; //元素进栈 } } }
void Pop1(SqStack *st) //出栈 { int i,x[5]; if(st->top==-1) { printf(\栈下溢出\\n\
} else { for(i=0;i<5;i++) { x[i]=st->data[st->top]; //元素出栈 st->top--; //移动栈顶位置 } printf(\出栈数组为:\\n\ for(i=0;i<5;i++) printf(\ printf(\ } }
int main() { SqStack L; SqStack *st=&L; ElemType e; int i,x[5],a; InitStack(st); Push1(st); Push1(st); Push1(st); Pop1(st); /*for(i=1;i<10;++i) { Push(st,i); printf(\入栈元素是:%d\\n\ } for(i=1;i<10;++i) { Pop(st,e); printf(\出栈元素是:%d\\n\ }*/ return 0; } 2.
#include
{ }
int sign=1; char a,b='('; stack
printf(\请输入算术表达式,以'#'为结束标志:\\n\a=getchar(); while(a!='#') { switch(a) { case '(': s.push(a); break; case ')': if(s.top()=='(') s.pop(); else sign=0; break; } if(sign==0) break; else a=getchar(); }
if(s.empty()==NULL) sign=0; if(sign==1) printf(\圆括号配对正确!\\n\else printf(\圆括号配对错误!\\n\