利用二叉树求解表达式的值

本文介绍如何使用二叉树来解析和求解数学表达式的值,重点讨论C语言实现过程,涉及到二叉树的构建、中缀表达式转化为后缀表达式以及栈的应用。
摘要由CSDN通过智能技术生成
<strong>#include<stdio.h>
#include<stdlib.h>
#define LIST_INIT_SIZE	100
#define LISTINCREMENT	10
#define STACK_INIT_SIZE     100  
#define STACKINCREMENT      10  
typedef char Elemtype;
typedef struct{
	Elemtype	*elem;
	int 		length;
	int		listsize;
}SqList;
typedef char TElemtype;

typedef struct BiTNode{
	TElemtype data;
	struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;

typedef char SElemtype;
typedef struct{
	SElemtype *base;
	SElemtype *top;
	int stacksize;
}SqStack;

#include"operation.h"

main()
{
	SqList L;BiTree T;
	InitBiTree(T);
	InitList(L);
	printf("请输入要操作的算术表达式:");
	while((L.elem[L.length]=getchar())!='\n')
	{
		if(L.length+1>=L.listsize)
    	{  
     	   L.elem=(Elemtype *)realloc(L.elem,  
                                    (L.listsize+LISTINCREMENT)*sizeof(Elemtype));  
     	   if(!L.elem)exit(-2);  
       		L.listsize+=LISTINCREMENT; 
		}
		L.
  • 7
    点赞
  • 45
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值