In the last of the expression conversion series I am presenting a program to convert a Postfix expression to an Infix expression. Here it is... #define Max 100 void pop (char*); void push(char*); char stack[MAX] [MAX]; int top = -1 main() { char s[MAX], str1[MAX], str2[MAX], str[MAX]; char s1[2],temp[2]; inti=0; clrscr( ) ; printf("\Enter the postfix expression; ") get(s); while (s[i]!`\0') { /*skip whitespace, if any*/ if(s[i] == ' ' ) i++; if (s[i] == `%' || s[i] == `*'|| s[i] == `-' || s[i] == `+' || s[i] == `/') { pop(str1); pop(str2); temp[0] =`('; temp[1] =`\0'; strcpy(str, temp); strcat(str, str2); temp[0] = s[i]; temp[1] = `\0' strcat(str,temp); strcat(str, str1); temp[0] =`)'; temp[1] =`\0'; strcat(str,temp); push(str); } else { temp[0]=s[i]; temp[1]=`\0'; strcpy(s1, temp); push(s1); } i++; } printf("\n%s", stack[0]); } void pop(char *a1) { strcpy(a1,stack[top]); top--; } void push (char*str) { if(top == MAX - 1) printf("\nstack is full"); else { top++; strcpy(stack[top], str); } } |