统计二叉树的结点数(C语言)
#include<stdio.h>
#include<stdlib.h>
typedef struct bitnode
{
char data;
struct bitnode *lchild,*rchild;
}Bitnode,*Bitree;
void CreatBintree(Bitree *T)
{
char ch;
scanf("%c",&ch);
if(ch=='0')
*T=NULL;
else
{
*T=(Bitnode *)malloc(sizeof(Bitnode));
(*T)->data=ch;
CreatBintree(&((*T)->lchild));
CreatBintree(&((*T)->rchild));
}
}
int CountBintree(Bitree *p)
{
int i=0;
if(*p)
{
i++;
CountBintree(&((*p)->lchild));
CountBintree(&((*p)->rchild));
}
return i;
}
void main()
{
Bitree root;
int m;
CreatBintree(&root);
m=CountBintree(&root);
printf("%d\n",m);
}
#include<stdlib.h>
typedef struct bitnode
{
char data;
struct bitnode *lchild,*rchild;
}Bitnode,*Bitree;
void CreatBintree(Bitree *T)
{
char ch;
scanf("%c",&ch);
if(ch=='0')
*T=NULL;
else
{
*T=(Bitnode *)malloc(sizeof(Bitnode));
(*T)->data=ch;
CreatBintree(&((*T)->lchild));
CreatBintree(&((*T)->rchild));
}
}
int CountBintree(Bitree *p)
{
int i=0;
if(*p)
{
i++;
CountBintree(&((*p)->lchild));
CountBintree(&((*p)->rchild));
}
return i;
}
void main()
{
Bitree root;
int m;
CreatBintree(&root);
m=CountBintree(&root);
printf("%d\n",m);
}
...全文
相关推荐
今年3月全国计算机等级考试二级C语言笔试试题.pdf
**二叉树的性质**:二叉树的叶子结点数与度为2的结点数存在一定的关系。在完全二叉树中,如果有n个结点,度为2的结点数为n-1,叶子结点数为n/2向上取整。4.
赫夫曼编码(C语言版本)
### 赫夫曼编码(C语言版本)#### 概述本文档提供了一个使用C语言实现的赫夫曼编码程序。
C语言中计算二叉树的宽度的两种方式
在C语言中,计算二叉树的宽度是一个常见的问题,主要涉及到数据结构和算法的知识。二叉树是一种每个节点最多有两个子节点的数据结构,通常分为左子节点和右子节点。
C语言实现二叉树的创建、插入、删除、遍历等操作
本篇将详细介绍如何用C语言实现二叉树的创建、插入、删除以及各种遍历方法,并探讨度为0、1、2的节点统计,以及排序二叉树的实现。1.
计算树的繁茂度-二叉树的繁茂度定义为各层结点数的最大值与树的高度的乘积.doc )
对于二叉树而言,其繁茂度是指各层结点数的最大值与树的高度的乘积。繁茂度可以用来衡量一棵二叉树的“密集程度”。


