Experiment 1 C Program To Convert Infix To Postfix: Code
Experiment 1 C Program To Convert Infix To Postfix: Code
#include<stdio.h>
char stack[20];
void push(char x)
{ stack[++top] = x; }
char pop()
{ if(top == -1)
return -1;
else
return stack[top--];}
int priority(char x)
{ if(x == '(')
return 0;
return 1;
return 2;}
void main()
{ char exp[20];
char *e, x;
scanf("%s",exp);
e = exp;
while(*e != '\0')
{ if(isalnum(*e))
printf("%c",*e);
push(*e);
printf("%c", x); }
else {
printf("%c",pop());
push(*e); }
e++; }
while(top != -1)
{ printf("%c",pop()); } }
Output: