Posts

Showing posts with the label Program to convert an expression in postfix form to an infix form

Program to convert an expression in postfix form to an infix form

#include #include #include #define MAX 50 struct postfix { char stack[MAX][MAX], target[MAX] ; char temp1[2], temp2[2] ; char str1[MAX], str2[MAX], str3[MAX] ; int i, top ; } ; void initpostfix ( struct postfix * ) ; void setexpr ( struct postfix *, char * ) ; void push ( struct postfix *, char * ) ; void pop ( struct postfix *, char * ) ; void convert ( struct postfix * ) ; void show ( struct postfix ) ; void main( ) { struct postfix q ; char expr[MAX] ; clrscr( ) ; initpostfix ( &q ) ; printf ( "\nEnter an expression in postfix form: " ) ; gets ( expr ) ; setexpr ( &q, expr ) ; convert ( &q ) ; printf ( "\nThe infix expression is: " ) ; show ( q ) ; getch( ) ; } /* initializes data member */ void initpostfix ( struct postfix *p ) { p -> i = 0 ; p -> top = -1 ; strcpy ( p -> target, "" ) ; } /* copies given expression to target string */ void setexpr ( struct postfix *p, char *c ) { strcpy ( p -> target, c ) ; } ...