C二叉樹求節點個數和葉子節點個數(遞歸形式)


 1 struct BiTree
 2 {
 3     struct BiTree *lchild;
 4     struct BiTree *rchild;
 5 };
 6 
 7 int Node(struct BiTree *T)
 8 {
 9     if(T == NULL)
10         return 0;
11     return 1+Node(T->lchild)+Node(T->rchild);
12 }
13 
14 int Leaf(struct BiTree *T)
15 {
16     if(T==NULL)
17         return 0;
18     if(T->lchild == NULL && T->rchild == NULL)
19         return 1;
20     return Leaf(T->lchild)+Leaf(T->rchild);
21 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM