二叉树的层次遍历和二叉树的应用的简单使用

1.二叉树的层次遍历

void levelTravse(BiTree root)
{
    if (root)
    {
        Queue q = CreateQueue();
        inQueue(q, root);
        while (emptyQueue(q))
        {
            BiTree e = outQueue(q);
            printf("%d", e->data);
            if (e->lchild)
            {
                inQueue(q, e->lchild);
            }
            if (e->rchild)
            {
                inQueue(q, e->rchild);
            }
            

        }
    }

}

 

2.计算二叉树的深度

int depthBinary(BiTree root) 
{
    if (!root)
    {
        return 0;
    }
    else
    {
        return depthBinary(root->lchild) > depthBinary(root->rchild) ? depthBinary(root->lchild) + 1 : depthBinary(root->rchild) + 1;
    }

}

 

好了,我们下回见,peace

posted @ 2020-08-09 22:10  野评测  阅读(183)  评论(0)    收藏  举报