题目:
代码:
#include<iostream>
using namespace std;
typedef struct BinaryTree
{
char data;
struct BinaryTree* leftchild;
struct BinaryTree* rightchild;
}BT;
void BinaryTreePreCreate(BT*& root)//注意要传引用创建二叉树
{
char a;
cin >> a;
if (a == '#')
root = NULL;
else
{
root = (BT*)malloc(sizeof(BT));
root->data = a;
BinaryTreePreCreate(root->leftchild);
BinaryTreePreCreate(root->rightchild);
}
}
int Count = 0;//全局变量记录空的个数
void BinaryTreeNullDomain(BT* root)
{
if (root == NULL)
{
Count++;
return;
}
BinaryTreeNullDomain(root->leftchild);
BinaryTreeNullDomain(root->rightchild);
}
int main()
{
BT* tree;
BinaryTreePreCreate(tree);
BinaryTreeNullDomain(tree);
printf("%d", Count);
return 0;
}