求树的深度

旧城冷巷雨未停 提交于 2019-12-04 16:34:33
#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;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!