check Errors in this code:
#include<stdio.h>
#include<conio.h>
struct stack
{
char s[30];
int top;
} st;
void main()
{
char infix[30];
void intopost(char infix[30]);
clrscr();
printf("\n Enter The Infix Notation:");
scanf("%s",&infix);
intopost(infix);
getch();
}
void intopost(char infix[30])
{
st.top=-1;
st.top=st.top+1;
st.s[st.top]='$';
char postfix[30];
int i,j;
char ch;
int instack(char ch);
int incoming (char ch);
void push(char item);
char pop();
j=0;
for(i=0; infix[i]!='\n'; i++)
{
ch=infix[i];
while (instack(st.s[st.top])>incoming(ch))
{
postfix[j]=pop();
j++;
}
if(instack(st.s[st.top])!=incoming(ch))
push(ch);
else
pop();
}
while((ch=pop())!='$')
{
postfix[j]=ch;
j++;
}
postfix[j]='\0';
printf("\n The Postfix Notation Is:%s",postfix);
}
int instack(char ch)
{
int priority;
switch(ch)
{
case'+':
case'-':
priority=2;
break;
case'*':
case'/':
priority=4;
break;
case'^':
priority=5;
break;
case'(':
priority=0;
break;
case'$':
priority=-1;
break;
default:
priority=8;
}
return priority;
}
int incoming(char ch)
{
int priority;
switch (ch)
{
case'+':
case'-':
priority=1;
break;
case'*':
case'/':
priority=3;
break;
case'^':
priority=6;
break;
case'(':
priority=9;
break;
case')':
priority=0;
break;
default:
priority=7;
}
return priority;
}
void push(char item)
{
st.top++;
st.s[st.top]=item;
}
char pop()
{
char e;
e=st.s[st.top];
st.top--;
return e;
}
Answers
Answered by
1
Answer:
I am your follower . Please follow me back . Please !!!
Similar questions