#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
typedef struct{
char *base;
char *top;
int stacksize;
}SqStack1;
typedef struct{
double *base;
double *top;
int stacksize;
}SqStack2;
SqStack1 OPTR;
SqStack2 OPND;
double EvaluateExpression();
void CHAR_InitStack(SqStack1 &S);
void DOUBLE_InitStack(SqStack2 &S);
char CHAR_GetTop(SqStack1 S);
double DOUBLE_GetTop(SqStack2 S);
int CHAR_Push(SqStack1 &S , char e);
int DOUBLE_Push(SqStack2 &S , double e);
char CHAR_Pop(SqStack1 &S , char &e);
double DOUBLE_Pop(SqStack2 &S , double &e);
char Precede(char a,char b);
double Operate ( double d ,char e,double f);
int In(char c);
int main(void)
{
double result;
printf("*************************\n");
printf("* 表达式计算 *\n");
printf("*************************\n");
printf("请输入一组表达式(以#号结束):\n");
result = EvaluateExpression();
printf("\n\n计算结果是(结果保留两位小数):%.2f\n\n\n",result);
}
void CHAR_InitStack(SqStack1 &S)
{
S.base=(char *)malloc(STACK_INIT_SIZE * sizeof(char));
if(!S.base)exit(OVERFLOW);
S.top = S.base;
S.stacksize = STAC
C/C++ 中缀表达式转换成后缀表达式并求值
最新推荐文章于 2024-07-29 20:53:35 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)