遍歷二叉樹口訣 二叉樹求葉子結(jié)點個數(shù)的算法(遞歸遍歷)?
二叉樹求葉子結(jié)點個數(shù)的算法(遞歸遍歷)?Int BTREE depth(BT->lchild){//find the depth of binary tree if(BT==null)//empt
二叉樹求葉子結(jié)點個數(shù)的算法(遞歸遍歷)?
Int BTREE depth(BT->lchild){//find the depth of binary tree if(BT==null)//empty tree returns 0return 0else{Int dep1=BTREE depth(BT->lchild)//遞歸調(diào)用逐層分析Int dep2=BTREE depth(BT->rchild)if(dep1>dep2)return dep2 1}}Int leave(bitnode*BT){//find二叉樹中的葉節(jié)點數(shù)if(BT==null)返回0else{if(BT->lchild==null)&這是學(xué)習(xí)數(shù)據(jù)結(jié)構(gòu)的練習(xí)。它使用遞歸形式。理解的時候需要考慮一下,但是函數(shù)相對簡單。