李翰


私信TA

用户名:2018007

访问量:1938

签 名:

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

等  级
排  名 1348
经  验 2957
参赛次数 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 人评分

  评论区

  • «
  • »