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;
    }
    
    齐芒行,川锋明!
  • 相关阅读:
    三位水仙花数
    常用Json
    毫秒数日前格式化
    常用ajax请求
    T-SQL应用,视图、存储过程、触发器、游标、临时表等
    SQL2-子查询、join查询
    SQL1-(增删改查、常用函数)
    html回车事件
    插入数据,返回最新id
    iframe高度自适应
  • 原文地址:https://www.cnblogs.com/qimang-311/p/13777711.html
Copyright © 2011-2022 走看看