zoukankan      html  css  js  c++  java
  • 二叉树

    #include <bits/stdc++.h>
    using namespace  std;
    #define ll long long
    struct edge{
       int data;
       struct edge *left;
       struct edge *right;
    };
    struct edge *build(struct edge *T, char F)
    {
        struct edge *p;
        p = (edge*)malloc(sizeof(edge));
        if(!T)
        {
            puts("是否输入根节点");
            char a = getchar();
            while (a!='N'&&a!='Y')getchar();
            if (a == 'N')return NULL;
            int x;
            puts("请输入x");
            cin>>x;
            p -> data = x;
        }
        else
        {
            if (F == 'L')
            {
                puts("是否输入左根节点");
                char a = getchar();
                while (a!='N'&&a!='Y')getchar();
                if (a == 'N')return NULL;
                int x;
                puts("请输入左节点x");
                cin>>x;
                p -> data =x;
            }
            else if (F == 'R')
            {
                puts("是否输入右根节点");
                char a = getchar();
                while (a!='N'&&a!='Y')getchar();
                if (a == 'N')return NULL;
                int x;
                puts("请输入右节点x");
                cin>>x;
                p -> data = x;
            }
        }
        p->left = build(p,'L');
        p->right = build(p,'R');
        return p;
    }
    void put(struct edge *T)
    {
        if ( T == nullptr )return;
        cout<<T->data<<endl;
        put(T->left);
        put(T->right);
    }
    int main()
    {
        struct edge *T;
        T = build(NULL,' ');
        put(T);
        return 0;
    }
    
    齐芒行,川锋明!
  • 相关阅读:
    宽带上网路由器设置
    ssh 与 irc
    Centos7 wifi
    linux无法挂载u盘
    virtualbox之usb设备的分配
    5G工程师必备!5G协议清单大全
    SSB的时频资源怎么确定的?UE那边怎么检测呢?
    link
    C++有用link
    C++学习路线转载
  • 原文地址:https://www.cnblogs.com/qimang-311/p/13777711.html
Copyright © 2011-2022 走看看