int LeavesCount(BiTree BT) { //返回二叉樹BT中葉子結點的個數 if(BT == NULL) return 0; //BT為空樹,返回0 int nCount = 0; if(!(BT->LChild || BT->RChild)) ++nCount; //BT為葉子結點,加1 else { //累加上左子樹上的葉子結點 nCount += LeavesCount(BT->LChild); //累加上右子樹上的葉子結點 nCount += LeavesCount(BT->RChild); } return nCount; } //---------------------------------------------------------------------- int NotLeavesCount(BiTree BT) { //返回二叉樹BT中非葉子結點的個數 if(BT == NULL || (!(BT->LChild || BT->RChild))) return 0; //若為BT為空樹或為葉子結點,返回0 else { int nCount = 1; //此時根結點也是一個非葉子結點 //累加上左子樹的非葉子結點個數 nCount += NotLeavesCount(BT->LChild); //累加上右子樹的非葉子結點個數 nCount += NotLeavesCount(BT->RChild); return nCount; } }
int LeavesCount(BiTree BT) { //返回二叉樹BT中葉子結點的個數 if(BT == NULL) return 0; //BT為空樹,返回0 int nCount = 0; if(!(BT->LChild || BT->RChild)) ++nCount; //BT為葉子結點,加1 else { //累加上左子樹上的葉子結點 nCount += LeavesCount(BT->LChild); //累加上右子樹上的葉子結點 nCount += LeavesCount(BT->RChild); } return nCount; } //---------------------------------------------------------------------- int NotLeavesCount(BiTree BT) { //返回二叉樹BT中非葉子結點的個數 if(BT == NULL || (!(BT->LChild || BT->RChild))) return 0; //若為BT為空樹或為葉子結點,返回0 else { int nCount = 1; //此時根結點也是一個非葉子結點 //累加上左子樹的非葉子結點個數 nCount += NotLeavesCount(BT->LChild); //累加上右子樹的非葉子結點個數 nCount += NotLeavesCount(BT->RChild); return nCount; } }