Posts

Showing posts with the label Program to convert an Infix expression to Prefix form.

Program to convert an Infix expression to Prefix form.

#include #include #include #include #define MAX 50 struct infix { char target[MAX] ; char stack[MAX] ; char *s, *t ; int top, l ; } ; 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 c ) ; void show ( struct infix ) ; void main( ) { struct infix q ; char expr[MAX] ; clrscr( ) ; initinfix ( &q ) ; printf ( "\nEnter an expression in infix form: " ) ; gets ( expr ) ; setexpr ( &q, expr ) ; convert ( &q ) ; printf ( "The Prefix expression is: " ) ; show ( q ) ; getch( ) ; } /* initializes elements of structure variable */ void initinfix ( struct infix *pq ) { pq -> top = -1 ; strcpy ( pq -> target, "" ) ; strcpy ( pq -> stack, "" ) ; pq -> l = 0 ; } /* reverses the given expression */ void setexpr ( struct infix *pq, char *str ) { pq -> s = str ; str...