表达式求值的完整程序,能够编译通过的

来源:百度知道 编辑:UC知道 时间:2024/06/02 22:25:07
希望注释齐全的!我是新手

#include<stdio.h>
#include<malloc.h>
#include<iostream.h>
#include<stdlib.h>
#include<math.h>
# define STACK_INIT_SIZE 100
# define STACK_INCREMENT 10
typedef char ElemType;

typedef struct
{
ElemType *base;
ElemType *top;
int stacksize;
}SqStack;
typedef struct
{
int *base;
int *top;
int stacksize;
}Int_SqStack;

char OP[11]={'+','-','*','/','^','(',')','#'};
char expr[40];
int precede[8][8]={
1,1,2,2,2,2,1,1,
1,1,2,2,2,2,1,1,
1,1,1,1,2,2,1,1,
1,1,1,1,2,2,1,1,
1,1,1,1,1,2,1,1,
2,2,2,2,2,2,3,0,
1,1,1,1,1,0,1,1,
2,2,2,2,2,2,0,3 };

int InitStack(SqStack &s)
{
if(!(s.base=(ElemType *)malloc(STACK_INIT_SIZE*sizeof(ElemType))))
exit(0);
s.top=s.base;
s.stacksize=STACK_INIT_SIZE;<