Program4_Infixtopostfix
Program4_Infixtopostfix
Program
should support for both parenthesized and free parenthesized expressions with the operators: +, -, *, /, %
(Remainder), ^ (Power) and alphanumeric operands.
#include<stdio.h>
#include<conio.h>
#include<string.h>
switch(symbol)
case '+':
case '%':
case '*':
case '^':
case '$':return 5;
default: return 8;
switch(symbol)
{
case '+':
case '%':
case '*':
case '^':
case '$':return 6;
case ')':return 0;
default: return 7;
int top,i,j;
char stack[30];
char symbol;
top=-1;
stack[++top]='#';
j=0;
{
symbol=infix[i];
postfix[j++]=stack[top--];
if (F(stack[top])!= G(symbol))
stack[++top]=symbol;
else
top--;
while(stack[top]!='#')
postfix[j++]=stack[top--];
postfix[j]='\0';
void main()
char infix[20];
char postfix[20];
clrscr();
scanf("%s",infix);
infix_postfix(infix,postfix);
printf("%s\n",postfix);
getch();