C表达式生成2叉树

来源:百度知道 编辑:UC知道 时间:2024/06/30 05:44:32
建立 "a+b*c-e/f" 代数表达试对应的二叉树.

我想要对应的程序代码! 谢谢!

//这是我课程设计中的一题,可以参考一下
//华南农业大学06级Lupkid
//表达式操作数,结果需在int范围内
#include "iostream"
#include "stdlib.h"
#include "stdio.h"
#include "malloc.h"
#include "math.h"
#define STACK_INIT_SIZE 10
#define STACKINCREMENT 5
#define OK 1
using namespace std;
typedef struct {//字符栈
char *base;
char *top;
int stacksize;
}SqStack;
typedef struct {//能存储char型和int型的混合类型,flag为1存储int,flag为0存储int
int data;
char chars;
int flag;
}mixtype;
typedef struct BiTNode {//树结点
mixtype data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;//树类型
BiTree BT;//定义BT树
typedef struct {//能存储数指针的栈
BiTree *base;
BiTree *top;
int stacksize;
}BTStack;
BTStack K1;//树指针栈K1
BTStack K2;//树指针栈K2
SqStack S;//字符栈S
SqStack T;//字符栈T
int InitStack(SqStack &S){//建立字符栈
S.base=(char *)malloc(STACK_IN