1 #include "stdio.h" 2 #include "stdlib.h" 3 #include "ctype.h" 4 #include "math.h" 5 #include "string.h" 6 7 struct stackNode{ 8 char data; 9 int value; 10 struct stackNode *nextPtr; 11 }; 12 13 typedef struct stackNode StackNode; 14 typedef StackNode *StackNodePtr; 15 16 int isOperator(char c); 17 void convertToPostfix(char infix[],char postfix[]); 18 int precedence(char opt1,char opt2); 19 void push(StackNodePtr *topPtr, char value); 20 char pop(StackNodePtr *topPtr); 21 void push2(StackNodePtr *topPtr, int value); 22 int pop2(StackNodePtr *topPtr); 23 char stackTop(StackNodePtr topPtr); 24 int isEmpty(StackNodePtr topPtr); 25 void printStack(StackNodePtr topPtr); 26 int calculate(int val1, int val2, char opt); 27 int evaluatePostfixExp(char postfix[]); 28 29 int main(void) 30 { 31 int i=0; 32 char ch; 33 char infix[100]; 34 char postfix[100]; 35 36 printf("Enter the expression: "); 37 38 while((ch = getchar()) != ' '){ 39 if(ch != ' '){ 40 if(isdigit(ch)){ 41 infix[i++] = ch; 42 } 43 else if(isOperator(ch)){ 44 infix[i++] = ' '; 45 infix[i++] = ch; 46 infix[i++] = ' '; 47 }else if(ch == '('){ 48 infix[i++] = ch; 49 infix[i++] = ' '; 50 }else{ 51 infix[i++] = ' '; 52 infix[i++] = ch; 53 } 54 } 55 } 56 infix[i] = '