这段代码switch好像没有运行到,输入(1+2)*3#最后栈里不会输出元素,为什么,谢谢告知
#include <stdio.h> #include <stdlib.h>
#include <malloc.h>
#include <string.h>
#define maxsize 20
typedef struct{
char data[maxsize];
int top;
}Seqstack;
Seqstack s1,s2;
int main(){
char str[maxsize];
int i=0;
s1.top=s2.top=-1;
printf("输入以#为结束标志的算式\n");
scanf("%s",&str);
while(str[i]!='#'){
printf("%c",str[i]);
switch(str[i]){
case'(':
s1.data[++s1.top]=str[i];break;
case')':
while(s1.data[s1.top]!='('){
s2.data[++s2.top]=s1.data[s1.top--];
}
s1.top--;
break;
}i++;
}
while(s1.top>-1){
printf("%c\n",s1.data[s1.top--]);
}
return 0;
}