李翰


私信TA

用户名:2018007

访问量:1721

签 名:

题解里面有错误请指正,谢谢各位师傅。

等  级
排  名 1257
经  验 2936
参赛次数 2
文章发表 14
年  龄 0
在职情况 学生
学  校
专  业 计科

  自我简介:

TA的其他文章

解题思路:

注意事项:

参考代码:

    #include<stdio.h>

    #include<stdlib.h>

    #include<malloc.h>

    typedef struct tree{

        char data;

        struct tree *Lchlid,*Rchlid;

    }tree;


    tree *root;


    tree* build_tree(tree *root){

        char ch;

        scanf("%c",&ch);

        if (ch ==' ') {

            root=NULL;

        }

        else{

            root=(tree *)malloc(sizeof(tree));

            root->data=ch;

            root->Lchlid=build_tree(root->Lchlid);

            root->Rchlid=build_tree(root->Rchlid);

        }

        return root;


    void preprint(tree *root){

        if(root==NULL)

            return;

        else{

            printf("%c ",root->data);

            preprint(root->Lchlid);

            preprint(root->Rchlid);

        }

}

    void inprint(tree *root){

        if(root==NULL) return;

        else{

            inprint(root->Lchlid);

            printf("%c ",root->data);

            inprint(root->Rchlid);

    }

}


    void postprint(tree *root){

        if(root==NULL)

            return;

        else{

            postprint(root->Lchlid);

            postprint(root->Rchlid);

            printf("%c ",root->data);

    }

}


    int main (){

        tree *root;

        root=build_tree(root);

        preprint(root);

        printf("\n");

        inprint(root);

        printf("\n");

        postprint(root);

        return 0;

}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区