while(IsEmpty(OpHolder)!=1){
/******
最后如果堆栈中还有运算符号,则一并放到temp中
******/
Push('B',Whereat);
putc(' ',Temp);
putc(Top(OpHolder),Temp);
Pop(OpHolder);
}
MakeEmpty(OpHolder);
free(OpHolder);
}
/******判断类型,1为运算符号,0为操作数,-1为错误******/
int IsOperator(char ToCompare)
{
if (ToCompare == '(' || ToCompare == ')'|| ToCompare == '+' || ToCompare == '-'
|| ToCompare == '*'|| ToCompare == '/' || ToCompare == '^'|| ToCompare == '%')
{
return 1;
}
else if (ToCompare == '1' || ToCompare == '2'|| ToCompare == '3'
|| ToCompare == '4' || ToCompare == '5'|| ToCompare == '6'
|| ToCompare == '7'|| ToCompare == '8' || ToCompare == '9'
|| ToCompare == '0'|| ToCompare == '.')
{
return 0;
}
else{
return -1;
}
}
/******返回运算符号的优先级******/
int OperatorValue(char ValueToGive)
{
if (ValueToGive == '(')
return 6;
if (ValueToGive == ')')
return 5;
if (ValueToGive == '^')
return 3;
if (ValueToGive == '%')
return 2;
if (ValueToGive == '*')
return 2;
if (ValueToGive == '/')
return 2;
if (ValueToGive == '+')
return 1;
if (ValueToGive == '-')
return 1;
return 0;
}
/******计算后缀表达式******/
void Calculate(FILE *Change, Stack Whereat, FILE *Temp)
{
FStack Operands;
float looker;
char Op;
char spacefinder;
float answer = 0;
float NumA;
float NumB;
Operands = (Ptr_Fn)malloc(sizeof(struct FNode));
Operands->Next= NULL;
while ((IsEmpty(Whereat) != 1) && PrintError != 1)
{ /*循环直到Whereat空,或者遇到错误*/
if (Top(Whereat) == 'A'){
fscanf(Temp," ",&spacefinder);