Posts

Showing posts with the label Program to evaluate an epression entered in postfix form

Program to evaluate an epression entered in postfix form

#include #include #include #include #include #define MAX 50 struct postfix { int stack[MAX] ; int top, nn ; char *s ; } ; void initpostfix ( struct postfix * ) ; void setexpr ( struct postfix *, char * ) ; void push ( struct postfix *, int ) ; int pop ( struct postfix * ) ; void calculate ( struct postfix * ) ; void show ( struct postfix ) ; void main( ) { struct postfix q ; char expr[MAX] ; clrscr( ) ; initpostfix ( &q ) ; printf ( "\nEnter postfix expression to be evaluated: " ) ; gets ( expr ) ; setexpr ( &q, expr ) ; calculate ( &q ) ; show ( q ) ; getch( ) ; } /* initializes data members */ void initpostfix ( struct postfix *p ) { p -> top = -1 ; } /* sets s to point to the given expr. */ void setexpr ( struct postfix *p, char *str ) { p -> s = str ; } /* adds digit to the stack */ void push ( struct postfix *p, int item ) { if ( p -> top == MAX - 1 ) printf ( "\nStack is full." ) ; else { p -> top++ ; p -> sta...