0% found this document useful (0 votes)
4 views2 pages

4

The document contains a C program that converts infix expressions to postfix notation. It defines two functions, 'f' and 'g', to determine operator precedence and associativity, respectively. The main function prompts the user for an infix expression, processes it, and outputs the corresponding postfix expression.

Uploaded by

muskaanthakur081
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

4

The document contains a C program that converts infix expressions to postfix notation. It defines two functions, 'f' and 'g', to determine operator precedence and associativity, respectively. The main function prompts the user for an infix expression, processes it, and outputs the corresponding postfix expression.

Uploaded by

muskaanthakur081
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<stdio.

h>
#include<string.h>
int f(char symbol)
{
switch(symbol)
{
case '+':
case '-':return 2;
case '*':
case '%':
case '/':return 4;
case '^':
case '$':return 5;
case '(':return 0;
case '#':return 8;
default:return 8;
}
}
int g(char symbol)
{
switch(symbol)
{
case '+':
case '-':return 1;
case '*':
case '%':
case '/':return 3;
case '^':
case '$':return 6;
case '(':return 9;
case '#':return 0;
default:return 7;
}
}

void infix_postfix(char infix[],char postfix[])


{
int top,i,j;
char s[30];
char symbol;
top=-1;
s[++top]='#';
j=0;
for(i=0;i<strlen(infix);i++)
{
symbol=infix[i];
while(f(s[top])>g(symbol))
postfix[j++]=s[top--];
if(f(s[top]!=g(symbol)))
s[++top]=symbol;
else
top--;
}
while(s[top]!='#')
postfix[j++]=s[top--];
postfix[j]='\0';
}
void main()
{
char infix[20],postfix[20];
printf("\n Enter the infix expn\t");
scanf("%s",infix);
infix_postfix(infix,postfix);
printf("\n After Evaluation %s",postfix);
}

You might also like