```c
#include <stdio.h>
typedef char Datatype;
typedef struct Node
{
Datatype data;
struct Node *lchild;
struct Node *rchild;
}BinTreeNode;
typedef BinTreeNode *BinTree;
void CreatBinTree(BinTree *T)//创建二叉树
{
char ch;
if((ch=getchar())==' ')
*T = NULL;
else{
*T=(BinTreeNode *)malloc(sizeof(BinTreeNode));
(*T)->data=ch;
CreatBinTree(&(*T)->lchild);
CreatBinTree(&(*T)->rchild);
}
}
int GetLeaves(BinTree root)//求叶子节点总数
{
static int leaf = 0;
if(root)
{
if(!(root->lchild||root->rchild))
leaf++;
GetLeaves(root->lchild);
GetLeaves(root->rchild);
}
return leaf;
}
int Depth(BinTree T)//递归求二叉树高度
{//对于非空二叉树,其深度等于某子树的深度加1
int dep1=0,dep2=0;
if(T==NULL) return 0;
else
{
dep1 = Depth(T->lchild);
dep2 = Depth(T->rchild);
return (dep1>dep2?dep1:dep2)+1;
}
}
void level(BinTree p)//BinTreeNode *p 层次遍历
{
int front,rear;
int Maxsize=50;
BinTreeNode *que[Maxsize];
front=rear=0;//定义循环队列
BinTreeNode *q;
if(p!=NULL)
{
rear=(rear+1)%Maxsize;
que[rear]=p;//根节点入队
while (front!=rear) {
q=que[front];//队头节点出队(队头节点出队后,其子孩子节点入队,则输出为层次遍历)
//visit(q);
if(q->lchild!=NULL)
{
rear=(rear+1)%Maxsize;
que[rear]=q->lchild;
}
if(q->rchild!=NULL)
{
rear=(rear+1)%Maxsize;
que[rear]=q->rchild;
}
}
}
}