p12 (Infix To Postfix)
p12 (Infix To Postfix)
#include<stdio.h>
#include<string.h>
#define MAX 20
char s[MAX];
int top=0;
int pop();
int main()
int i=0,j=0;
printf("\n\t\t~~~~~~~~~~~~~~\n");
scanf("%s", infix);
push('#');
for(i=0;i<strlen(infix); i++)
ch=infix[i];
if(isalnum(ch))
postfix[j++]=ch;
else
if(ch=='(')
push(ch);
else
if(ch==')')
while(s[top]!='(')
postfix[j++] = pop();
elem = pop();
else
postfix[j++]=pop();
push(ch);
while(s[top] != '#')
postfix[j++]=pop();
postfix[j]='\0';
switch(elem)
case '+':
case '-':
return(1);
case '*':
case '/':
return(2);
case '(':
}
}
++top;
s[top]=elem;
int pop()
char elem;
elem=s[top];
--top;
return(elem);
OUTPUT