设T是指向二叉树根结点的指针变量
//没有测试,我觉得可以。 你试试
typedef struct BTNode
{
ElemType data ;
struct BTNode *Lchild , *Rchild ;
}BTNode;
#define MAX_CNT 1000
void TreeScan(const BTNode *pRoot, int &nCnt1, int &nCnt2)
{
//pRoot 根节点
//nCnt1 叶子节点数
//nCnt2 非叶子节点数
void *pBuf[MAX_CNT] = {0}; // 存储所有节点指针
int nCnt = 0; // 记录节点数
int nPos = ...全部
//没有测试,我觉得可以。
你试试
typedef struct BTNode
{
ElemType data ;
struct BTNode *Lchild , *Rchild ;
}BTNode;
#define MAX_CNT 1000
void TreeScan(const BTNode *pRoot, int &nCnt1, int &nCnt2)
{
//pRoot 根节点
//nCnt1 叶子节点数
//nCnt2 非叶子节点数
void *pBuf[MAX_CNT] = {0}; // 存储所有节点指针
int nCnt = 0; // 记录节点数
int nPos = 0; // 游标, 在pBuf上用
BTNode *p = pRoot;
nCnt1 = nCnt2 = 0;
if( p == NULL ) return;
pBuf[nCnt++] = p;
while( nPosLchild ) pBuf[nCnt++] = p->Lchild;
if( p->Rchild ) pBuf[nCnt++] = p->Rchild;
nPos++;
}
for(int n=0; nLchild || p->Rchild ) nCnt2++;
else nCnt1++;
}
return;
}
。收起