/// This program is a implementation of shunting yard algorithm to convert an infix expression to post fix expression, This is a extension of the stack
//program published earlier
/* * While there are tokens to be read:
* Read a token.
* If the token is a number, then add it to the output queue.
* If the token is a function token, then push it onto the stack.
* If the token is a function argument separator (e.g., a comma):
* Until the topmost element of the stack is a left parenthesis, pop the element from the stack and push it onto the output queue.
If no left parentheses are encountered, either the separator was misplaced or parentheses were mismatched.
* If the token is an operator, o1, then:
* while there is an operator, o2, at the top of the stack, and either
o1 is associative or left-associative and its precedence is less than (lower precedence) or equal to that of o2, or
o1 is right-associative and its precedence is less than (lower precedence) that of o2,
pop o2 off the stack, onto the output queue;
* push o1 onto the stack.
* If the token is a left parenthesis, then push it onto the stack.
* If the token is a right parenthesis:
* 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.
* When there are no more tokens to read:
* While there are still operator tokens in the stack:
* If the operator token on the top of the stack is a parenthesis, then there are mismatched parenthesis.
* Pop the operator onto the output queue.
* Exit.
*/
//Program downloaded from GeeksPlanet.net
//http://geeksplanet.net/2008/10/c-programming/program-to-convert-infix-expression-to-postfix-in-c-shunting-yard-algorithm/
#include
#include
#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;
printf("\nEnter an infix expression:");
scanf("%s",infix);
printf("\nThe infix expresson is %s",infix);
length=strlen(infix);
for(i=0;i