怎样建立代数式的二叉树?
来源:百度知道 编辑:UC知道 时间:2024/09/20 21:44:39
建立的binary search tree为:
-
+ /
A B * E
# # # # C D # #
怎样建立这个树呢?
谢谢了!
#include<stdio.h>
#include<stdlib.h>
#include<fstream.h>
#include<crtdbg.h>
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int Status; // Status是函数的类型,其值是函数结果状态代码,如OK等
typedef struct tree{
char c;
struct tree *lchild;
struct tree *rchild;
}tree,*Tree;
//***************************************************************************
//栈的储存结构
typedef struct{
//运算符栈
char *base;
char *top;
int stacksize;
}SqStack1;
typedef struct{
//运算数栈
Tree *base;
Tree *top;
int stacksize;
}SqStack2;
//***************************************************************************
//以下是运算符栈的基本操作函数
Status InitStack(SqStack1 &S){
//初始化一个栈
S.base=(char