我正在编写将中缀表达式转换为反向表示法的代码,但我的程序在执行文件时崩溃
typedef struct stack
{
char a[400];
int top;
}
stack;
stack s;
void push(char *,int);
int pop();
int main()
{
char x[400];
int len,i,y;
puts("Enter string");
scanf("%s",x);
len=strlen(x);
for(i=0;i<len;i++)
{
//considering user is entering only the small alphabets
if((x[i])>=97&&x[i]<=122)
printf("%s",x[i]);
else
//if encountering the operator then pushing it into stack
if(x[i]=='/'||x[i]=='*'||x[i]=='+'||x[i]=='-')
{
push(x,i);
}
else if(x[i]=='(')
continue;
//When encountering the ')' then popping the operator
else
{
y=pop();
printf("%c",y);
}
}
return 0;
}
传递数组及其大小作为参数
void push(char *x,int i)
{
stack s;
s.top++;
s.a[s.top]=x[i];
}
在找出“)”时返回弹出的运算符
int pop()
{
stack s;
int temp;
temp=s.a[s.top];
s.top--;
return temp;
}