二叉树的代码 c++
来源:百度知道 编辑:UC知道 时间:2024/09/21 00:33:11
根据输入字符串创建树或二叉树,输出树或二叉树的先根遍历和后根遍历序列,计算并输出树或二叉树的深度和叶子的个数。
谢谢,100悬赏
谢谢,100悬赏
输入字符串,是算术表达式的吧?
否则,如何根据它创建二叉树呢?
叶子的个数,就是操作数的个数。
百度一下,多少啊 ……
看书:数据结构算法设计,很好,专门为考研用的,你那个问题我正在看,还不怎么会,希望这本书对你有用。祝你好运!
目前我头痛这题
看那本专门的书籍啊
//我数据结构实验代码,以前学数据结构的时候写的
//主函数自己写,这个是头文件
#include<iostream>
using namespace std;
typedef char elemType;
struct bnode
{
bnode *lchild,*rchild;
elemType data;
};
class BinaryTree
{
public:
BinaryTree();
void create(bnode* &tempR);
void visite(bnode *T);
void preorder(bnode *T);
void inorder(bnode *T);
void postorder(bnode *T);
int BTreeLeafCount(bnode *BT);
bnode *root;
private:
int count;
};
BinaryTree::BinaryTree()
{
root = NULL;
count = 0;
}
void BinaryTree::create(bnode* &tempR)
{
elemType x;
cin>>x;
if(x == '.')
{
tempR = NULL;
} <