二叉树的遍历也常常用来对二叉树进行计数。
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#define MAXSIZE 100
typedef char ElemType;
typedef struct Node
{
ElemType data;
struct Node *lchild;
struct Node *rchild;
}*BitTree,BitNode;
void CreateBitTree2(BitTree *T,char str[]);//非递归创建二叉树
void DestroyBitTree(BitTree *T);//销毁二叉树
int LeafNum(BitTree T);//统计二叉树中的叶子结点的数目
int NotLeafCount(BitTree T);//统计二叉树中的非叶子结点的数目
int BitTreeDepth(BitTree T);//计算二叉树的深度
#include "LinkBiTree.h"
void CreateBitTree2(BitTree *T,char str[])//非递归创建二叉树
{
char ch;
BitTree stack[MAXSIZE];
int top = -1;
int flag,k;
BitNode *p;
*T = NULL,k = 0;
ch = str[k];
while(ch != '\0')
{
switch(ch)
{
case '(':