#include #include #include #include #include typedef float elemtype; struct stack { elemtype *stack; short top; short stackmaxsize; }; static void initstack ( stack &s,int ms ) { s.stack=new elemtype[ms]; if ( !s.stack ) { cerr<<"memory full!"<>ch; while ( ch!='@' ) { switch ( ch ) { case'+': x=pop ( s ) +pop ( s ); break; case'-': x=pop ( s ); x=pop ( s )-x; break; case'*': x=pop ( s ) *pop ( s ); break; case'/': x=pop ( s ); if ( x!=0 ) x=pop ( s ) /x; else { cerr<<"divide by 0!"<>x; } push ( s,x ); ins>>ch; } // x=pop(s); // return x; if ( !stackempty ( s ) ) { x=pop ( s ); if ( !stackempty ( s ) ) { cerr<<"expression error!"<=precedence ( ch ) ) { s2[j++]=w; pop ( r ); w=peek ( r ); } push ( r,ch ); ch=s1[++i]; } else { while ( isdigit ( ch ) ||ch=='.' ) { s2[j++]=ch; ch=s1[++i]; } s2[j++]=' '; } } ch=pop ( r ); while ( ch!='@' ) { if ( ch=='(' ) { cerr<<"expression error!"<