prog4
prog4
Infix Expression
It follows the scheme of <operand><operator><operand> i.e. an <operator> is
preceded and succeeded by an <operand>. Such an expression is termed infix
expression. E.g., A+B
Postfix Expression
It follows the scheme of <operand><operand><operator> i.e. an <operator> is
succeeded by both the <operand>. E.g., AB+
/*
* This program converts infix expression to postfix expression.
* This program assume that there are Five operators: (*, /, +, -,^)
in infix expression and operands can be of single-digit only.
* This program will not work for fractional numbers.
* Further this program does not check whether infix expression is
valid or not in terms of number of operators and operands.
*/
#include<stdio.h>
#include<stdlib.h> /* for exit() */
#include<ctype.h> /* for isdigit(char ) */
#include<string.h>
if(top <0)
{
printf("stack under flow: invalid infix expression");
getchar();
/* underflow may occur for invalid expression */
/* where ( and ) are not matched */
exit(1);
}
else
{
item = stack[top];
top = top-1;
return(item);
}
}
/* define function that is used to determine whether any symbol is operator or not
(that is symbol is operand)
* this fucntion returns 1 if symbol is opreator else return 0 */
i=0;
j=0;
item=infix_exp[i]; /* initialize before loop*/
return 0;
}