//Infix To Postfix
#include <stdio.h>
#include <stdlib.h>
#define MAX 20
typedef struct
{
int data[MAX];
int top;
}STACK;
void initstack(STACK *ps)
{
ps->top=-1;
}
void push(STACK *ps, int num)
{
ps->top++;
ps->data[ps->top]=num;
}
int pop(STACK *ps)
{
return(ps->data[ps->top--]);
}
int isempty(STACK *ps)
{
return(ps->top==-1);
}
int isfull(STACK *ps)
{
return(ps->top=MAX-1);
}
void main()
{
void postfix(char in[], char post[]);
char in[20], post[20];
printf("Enter The Fully Parenthesized Infix Expression:\t");
scanf("%s", in);
postfix(in, post);
printf("\n The Postfix String Is: %s",post);
}
void postfix(char in[], char post[])
{
int i, j=0;
char ch1;
STACK s1;
initstack(&s1);
for(i=0; in[i]!='\0'; i++)
{
switch(in[i])
{
case '+':
case '-':
case '*':
case '/':
case '%':
case '(': push(&s1, in[i]);
break;
case ')': while((ch1=pop(&s1)) != '(')
post[j++]=ch1;
break;
default: post[j++]=in[i];
}
}
while(!isempty(&s1))
post[j++]=pop(&s1);
post[j]='\0';
}