Академический Документы
Профессиональный Документы
Культура Документы
// INFIX TO POSTFIX
#include<stdio.h>
#include<conio.h>
#include<string.h>
case '*':
return 2;
break;
case '/':
return 2;
break;
case '+':
return 1;
break;
case '-':
return 1;
break;
default : return 0;
}
}
int main()
{
char inf[100],pos[100],s[100];char x,y;
int i=0,j=0,top=-1;
printf("\nEnter the Infix Notation: ");
gets(inf);
for(i=0;inf[i]!='\0';i++)
{
if (isalnum(inf[i]))
pos[j]=inf[i];
j++;
else if(inf[i]=='(')
push(s,&top,inf[i]);
else if(inf[i]==')')
y=pop(s,&top);
while(y!='(')
pos[j]=y;
j++;
y=pop(s,&top);
else
push(s,&top,inf[i]);
else
while((priority(s[top]))>=(priority(inf[i])))
pos[j]=pop(s,&top);
j++;
push(s,&top,inf[i]);
}
}
while(top>-1)
{
pos[j]=pop(s,&top);
j++;
}
pos[j]='\0';
printf("\nThe Postfx Notation is: ");
puts(pos);
getch();
}