• 求树的深度


    可能编译时会有些语法小错误(比如分号,->,等),很容易就自己纠正了哦,思路绝对是完全正确的,所以用的话就自己试着改改吧,直接复制粘贴,就正确,岂不是太没写代码体验了,自己改改才印象更加深刻的呢()~~~~;

    #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:
    ";
        CreateBiTree(tree);
        cout<<"deepth is:"<<Depth(tree)<<endl;
    }
    
  • 相关阅读:
    2019年4月18日 查询功能 2
    bzoj3601
    bzoj2693
    bzoj2440
    bzoj3529
    bzoj2820
    BZOJ2813
    BZOJ4515
    AtCoder Grand Contest 001 题解
    BZOJ2757
  • 原文地址:https://www.cnblogs.com/ygjzs/p/11874585.html
Copyright © 2020-2023  润新知