#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int data;
struct node* left;
struct node* right;
}Node;
typedef struct tree
{
struct node* root;
}Tree;
char insert(Tree *tree,char value)
{
if(value==NULL)
return;
else
{
Node* node=malloc(sizeof(node));
node->data=value;
node->left=insert(node->left,value);
node->right=insert(node->right,value);
}
return value;
}
int get_hight(Node *node)
{
int max;
if(node==NULL)
{
return 0;
} else
{
int left_h=get_hight(node->left);
int right_h=get_hight(node->right);
int max=left_h;
if(right_h>left_h)
{
max=right_h;
}
}
max=max+1;
printf("%d",max);
return max;
}
int count=0;
int countleaf(Node *node,int count)
{
if(node==NULL)
{
return;
}
if(node!=NULL&&node->left==NULL&&node->right==NULL)
{
count++;
}
if(node!=NULL)
{
countleaf(node->left,count);
countleaf(node->right,count);
}
return count;
}
int main()
{
Node *node=NULL;
Tree *tree=node;
int i,j=0;
char a[15]={'A','B','D',' ',' ',' ','C','E',' ','G',' ',' ','F',' ',' '};
for(i=0;i<15;i++)
{
insert(node,a[i]);
printf("%c",a[i]);
}
countleaf(node,j);
printf("%d",j);
get_hight(node);}
输出结果确实这样