int leafnum(treeNode * pNode) { int count = 0; if (!pNode) return 0; if (!pNode->ld && !pNode->rd) ++count; count += leafnum(pNode->ld); count += leafnum(pNode->rd); return count; }
int main(int argc, char ** argv) { treeNode * root = createTree(); if (!root) return -1; printf("\n------------------\n"); LDRTree(root); printf("\n------------------\n"); DLRTree(root); printf("\n------------------\n"); LRDTree(root); printf("\n叶子结点个数 %d\n", leafnum(root)); printf("\n二叉树层高 %d\n", getMaxLevel(root)); showTree(root); return 0; }
int main() { Bitree root; creat(&root); initstack(); preorder(root); printf("\n"); printf("%d\n\n",Two); output(root); printf("\n"); tree(root,1); change(root); preorder(root); printf("\n"); int depth=treedepth(root); char ph[depth]; path(root,ph,depth); print(root,1); int leaf=leafnum(root); printf("%d",leaf); }