BinaryTree_CountLeafNode

/******************************************************************************************************
  * @file name:		  :StacksSimulateQueue
  * @brief  		  :两个栈实现队列的功能
  * @author 		  :wvjnuhhail@126.com
  * @date 			  :2024/05/04
  * @version          :V1.0
  * @property 		  :暂无
  * @note   		  :None
  * CopyRight (c)  2023-2024   wvjnuhhail@126.com   All Right Reseverd
******************************************************************************************************/
#include <stdio.h>
#include <stdbool.h>


typedef struct insertSort
{
    struct insertSort* lchild;
    struct insertSort* rchild;
}Tnode_t;

/********************************
 *  funName:     BinaryTree_CountLeafNode
 *  funtion:     计算一颗二叉树的所有叶子节点的数量        
 *  Argument:
 *               @n1  :  n1记录左子树叶子节点
 *               @n2  :  n2记录右子树叶子节点
 * 
 *  返回结果:     二叉树的深度,类型为整型
 *  注意事项:     None
 *  函数作者:    wvjnuhhail@126.com
 *  创建日期:     2024/05/04
 *  修改历史:    None
 *  函数版本:    V1.0
 * ********************************/

int BinaryTree_CountLeafNode(Tnode_t *root)
{
    //n1记录左子树叶子节点
    int n1;

    //n2记录右子树叶子节点
    int n2;

    //递归函数提前编写终止条件
    if(NULL == root)
    {
        //空树的情况,返回0
        return 0;
    }
    else if(root -> lchild == NULL && root -> rchild == NULL)
    {
        //说明只有一个根节点,那么根节点就是叶子节点
        return 1;
    }
    else{

        //二叉树有子树,需要计算左子树的叶子节点和右子树的叶子节点
        n1 = BinaryTree_CountLeafNode(root -> lchild);
        n2 = BinaryTree_CountLeafNode(root -> rchild);
    }
}





posted @ 2024-05-04 22:31  WJnuHhail  阅读(2)  评论(0编辑  收藏  举报