Home > Back-end >  Infix expressions to postfix expression problems don't know where the code bigwig, please
Infix expressions to postfix expression problems don't know where the code bigwig, please

Time:09-24

# include
# include
# include
# include
# define STACK_INIT_SIZE 30
# define STACKINCREMENT 10
# define OVERFLOW - 2
# define OK 1
# define the ERROR 0
# define TRUE 1
# define FALSE 0
30//# define N the length of the one-dimensional array
Typedef char SElemType;
Typedef int the Status;
Typedef struct
{SElemType * base;
SElemType * top;
Int stacksize;
} SqStack;
The Status InitStack (SqStack & amp; S)
{S.b ase=(SElemType *) malloc (STACK_INIT_SIZE * sizeof (SElemType));
if(! S.b ase) exit (OVERFLOW);
S.t op=S.b ase;
S.s tacksize=STACK_INIT_SIZE;
return OK;
}

The Status of Pop (SqStack & amp; S, SElemType & amp; E)
{if (S.t op=S.b ase) return the ERROR;
E=* (-- S.t op);
return OK;
}
SElemType GetTop (SqStack S)
{SElemType e=' ';
If (S.t op> S.b ase)
E=* (-- S.t op);
Return e;
}

The Status of Push (SqStack & amp; S, SElemType e)
{if (S.t op - S.b ase>=S.s tacksize)
{S.b ase=(SElemType *) realloc (S.b ase, (S.s tacksize + STACKINCREMENT) * sizeof (SElemType));
if(! S.b ase) exit (OVERFLOW);
S.t op=S.b ase + S.s tacksize;
S.s tacksize +=STACKINCREMENT;
}
* S.t op=e;
S.t op++;
return OK;
}

The Status InOP (SElemType c)
{switch (c)
{case '+' : case '-' : case: '*' case '/' : case ') : case '(' : a case of' # ':
Return TRUE; break; }
return FALSE;
}


SElemType Precede (SElemType curtop, SElemType input)
{SElemType order=' ';
The switch (input)
{case '+' : case '-' :
The switch (curtop) {
Case: '+' case '-' : case: '*' case '/' : case ') : the order='& gt; '; break;
Case '(' : case' # ': order=' & lt; '; break; }
break;
Case: '*' case '/' :
The switch (curtop) {
Case: '+' case '-' : case '(' : case' # ': order=' & lt; '; break;
Case: '*' case '/' : case ') : the order='& gt; '; break; }
break;
Case '('
The switch (curtop) {
Case: '+' case '-' : case: '*' case '/' : case '(' : case' # ': order=' & lt; '; break; }
break;
Case ') :
The switch (curtop) {
Case: '+' case '-' : case: '*' case '/' : case ') : the order='& gt; '; break;
='=' case '(' : the order; break; }
break;
Case '#' :
The switch (curtop) {
Case: '+' case '-' : case: '*' case '/' : case ') : the order='& gt; '; break;
='=' case '#' : the order; break; }
break;
}
Return the order;
}

Void Change (SqStack & amp; S, SElemType STR [])
{
Int I=0; SElemType e, x;
Push (S, '#');
While (STR [I]!='#' | | GetTop (S)!='#')
{if (! InOP (STR) [I])
{printf (" % c ", STR [I]); i++; }
The else
The switch (Precede (GetTop (S), the STR [I]))
{case '& lt; ': Push (S, STR [I]); i++; break;
Case: '=' Pop (S, e); i++; break;
Case '& gt; ': Pop (S, x); Printf (" % c ", & amp; X); break;

}

}
}



Int main ()
{SElemType STR [N].//with a one-dimensional array to store the postfix expression
SqStack S;
InitStack (S);
Printf (" please enter the infix expression to # to end the sign: \ n ");
Gets (STR);
Change (S, STR);
return 0;
}

CodePudding user response:

This question is hard to get answer, did not say something wrong, also did not provide other information

CodePudding user response:

Thank you for your reminding,

CodePudding user response:

  • Related