首页 > 其他 > 详细

求树的深度

时间:2019-11-17 00:16:30      阅读:98      评论:0      收藏:0      [点我收藏+]
#include<iostream>
using namespace std;

typedef struct BiNode{
    char data;
    struct BiNode *lchild,*rchild;
}BiTNode,*BiTree;

void CreateBiTree(BiTree &T){
    char ch;
    cin >> ch;
    if(ch=='#') T=NULL;
    else{
        T=new BiTNode;
        T->data=ch;
        CreateBiTree(T->lchild);
        CreateBiTree(T->rchild);
    }
}

int Depth(BiTree T){
    int m,n;
    if(T==NULL) retue 0;
    else{
        m=Depth(T->lchild);
        n=Depth(T->rchild);
        if(m>n) return(m+1);
        else{
            return (n+1);
        }
    }
}

void main(){
    BiTree tree;
    cout<<"please input:\n";
    CreateBiTree(tree);
    cout<<"deepth is:"<<Depth(tree)<<endl;
}

求树的深度

原文:https://www.cnblogs.com/ygjzs/p/11874585.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!