Я пишу код для преобразования инфиксного выражения в обратную нотацию, но моя программа дает сбой при выполнении файла
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;
}