二叉链表存储表达式求值

#题目

表达式(a-(b+c)) * (d/e)存储在如图的一棵二叉树中(树结点data域为字符型),编写程序求该表达式的值(表达式中的操作数都是一位的整数)

在这里插入图片描述
#测试程序

#include<iostream>
using namespace std;

//二叉树链表结点
typedef struct BTNode{
   
	struct BTNode *lchild;
	struct BTNode *rchild;
	char data;	
}BTNode;

//构造二叉树
BTNode *createbinarytree()	//利用递归思想构造二叉树
{
   
	char element;
	cin>>element;	//输入二叉树的根节点的data值
	
	BTNode *T;
	if(element!='s')	//设置终止条件,s代表stop
	{
   
		T=(BTNode*)malloc(sizeof(BTNode));
		T->data=element;
		cout<<"please input the left child node of "<<element<<endl;
		T->lchild=createbinarytree();
		cout<<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值