表达式求值怎样用二叉数构建

来源:百度知道 编辑:UC知道 时间:2024/05/29 09:27:10
有完整的源程序更好
主要帮我分析一下过程,给定一中缀表达式,怎样构建成一二叉数,用中序遍历得到后缀表达式,最后求值又怎么求的。要用到二叉数,不要只用到栈。
写错了 是用后序遍历得到后缀表达式

用中序遍历得到后缀表达式,
中序遍历得到后缀表达式?开玩笑吧?
我写过个建树的函数如下。

#include<stdio.h>
#include<stdlib.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=(