#include #include #include #include #define MAXCOLS 80 //NOTACION POSFIJA struct stack { int top; char items[MAXCOLS]; }ps; int empy (struct stack *ps) { if (ps->top==-1) return 1; else return 0; } int push (struct stack *ps, int x) { ps->items[++(ps->top)]=x; return 1; } int pop (struct stack *ps) { if (empty(ps)) { cout<<"\n SUBDESBORDE"; exit (1); } return (ps->items[ps->top--]); } int isoperand (char symb) { switch (symb) { case '+': return 1; case '-': return 1; case '*': return 1; case '/': return 1; default: return 0; } } void popandtest (struct stack *ps, char *px, int *pund) { if (empty(ps)) { *pund=1; return; } *pund=0; *px=ps->items [ps->top--]; return; } void postfix (char infix[], char postr[]) { int position, und; int outpos=0; char topsymb='+'; char symb; struct stack opstk; opstk.top=-1; for (position=0;(symb=infix[position])!='\0';position++) { if (isoperand(symb)) postr[outpos++]=symb; else { popandtest(&opstk,&topsymb,&und); while (!und) { postr[outpos++]=topsymb; popandtest(&opstk,&topsymb,&und); } if (!und) push(&opstk,topsymb); if (und || (symb !=')')) push(&opstk,symb); else topsymb=pop(&opstk); } while (!empty(&opstk)) postr[outpos++]=pop (&opstk); postr[outpos++]='\0'; return; } } main () { char infix[MAXCOLS]; char postr[MAXCOLS]; int pos=0; cout<<"Dame la Notacion "; infix[--pos]= '\0'; pos=0; while (infix[pos]!='\0') cout<<"La expresion original es: "<