This Program Is A Implementation of Shunting Yard Algorithm
This Program Is A Implementation of Shunting Yard Algorithm
* Read a token.
* Until the topmost element of the stack is a left parenthesis, pop the
element from the stack and push it onto the output queue.
* while there is an operator, o2, at the top of the stack, and either
* Until the token at the top of the stack is a left parenthesis, pop operators
off the stack onto the output queue.
* Pop the left parenthesis from the stack, but not onto the output queue.
* If the token at the top of the stack is a function token, pop it and onto the
output queue.
* If the stack runs out without finding a left parenthesis, then there are
mismatched parentheses.
* If the operator token on the top of the stack is a parenthesis, then there
are mismatched parenthesis.
* Exit.
*/
//http://geeksplanet.net/2008/10/c-programming/program-to-convert-infix-
expression-to-postfix-in-c-shunting-yard-algorithm/
#include<stdio.h>
#include<string.h>
#define size 10
char stack[size];
int tos=0,ele;
void push();
char pop();
void show();
int isempty();
int isfull();
char infix[30],output[30];
int prec(char);
int main()
int i=0,j=0,k=0,length;
char temp;
scanf("%s",infix);
length=strlen(infix);
for(i=0;i<length;i++)
output[j++]=infix[i];
}
//If an operator or a bracket is encountered...
else
push(infix[i]);
else
temp=pop();
output[j++]=temp;
push(infix[i]);
show();
else
push(infix[i]);
printf("\nThe pushed element is:%c",infix[i]);
show();
else
if(infix[i]=='(')
push(infix[i]);
if(infix[i]==')')
temp=pop();
while(temp!='(')
{output[j++]=temp;
//temp=pop();
temp=pop();}
}
}
while(tos!=0)
output[j++]=pop();
stack[tos]=ele;
tos++;
char pop()
tos--;
return(stack[tos]);
void show()
int x=tos;
printf("--The Stack elements are.....");
while(x!=0)
printf("%c, ",stack[--x]);
if(symbol== '(')
return 0;
if(symbol== ')')
return 0;
if(symbol=='+' || symbol=='-')
return 1;
if(symbol=='*' || symbol=='/')
return 2;
if(symbol=='^')
return 3;
return 0;