Posts

Showing posts with the label Program to convert an Infix form to Postfix form

Program to convert an Infix form to Postfix form

#include #include #include #include #define MAX 50 struct infix { char target[MAX] ; char stack[MAX] ; char *s, *t ; int top ; } ; void initinfix ( struct infix * ) ; void setexpr ( struct infix *, char * ) ; void push ( struct infix *, char ) ; char pop ( struct infix * ) ; void convert ( struct infix * ) ; int priority ( char ) ; void show ( struct infix ) ; void main( ) { struct infix p ; char expr[MAX] ; initinfix ( &p ) ; clrscr( ) ; printf ( "\nEnter an expression in infix form: " ) ; gets ( expr ) ; setexpr ( &p, expr ) ; convert ( &p ) ; printf ( "\nThe postfix expression is: " ) ; show ( p ) ; getch( ) ; } /* initializes structure elements */ void initinfix ( struct infix *p ) { p -> top = -1 ; strcpy ( p -> target, "" ) ; strcpy ( p -> stack, "" ) ; p -> t = p -> target ; p -> s = "" ; } /* sets s to point to given expr. */ void setexpr ( struct infix *p, char *...