建立一棵二叉树,用二叉链表存储二叉树,计算二叉树中包含的结点个数。
输入描述:
输入的数据只有一组,是一棵二叉树的先序遍历序列,结点的值为一个小写字母,#号表示空结点,
如输入:a b d e # # f # # # c # #,数据之间空一个格,得到的二叉树如下。
( 图暂时不能上传,请同学们自己画出图)
输出描述:
输出二叉树的结点个数,空树输出NULL。
输入样例:
输入样例1:
a b c # # # d e # # f # #
输入样例2:
#
输出样例:
输出样例1:
6
输出样例2:
NULL
#include<iostream>
#include<stdio.h>
#include<cstdlib>
using namespace std;
static int count=0;
struct Node
{
char data;
Node *Lchild,*Rchild;
};
class BiTree
{
public:
BiTree(){root=Create(root);}
~BiTree(){Release(root);}
void print(){print(root);}
private:
Node *root;
Node *Create(Node *bt);
vo