题解 | #二叉树遍历#

二叉树遍历

https://www.nowcoder.com/practice/4b91205483694f449f94c179883c1fef

#include<stdio.h>
#include<stdlib.h>

char str[105];

struct BTNode{
    char c;
    struct BTNode* left;
    struct BTNode* right;
};

struct BTNode* Create(int* pi)
{
    if(str[*pi]=='#')
    {
        (*pi)++;
        return NULL;
    }
    struct BTNode* root=(struct BTNode*)malloc(sizeof(struct BTNode));
    root->c=str[(*pi)++];
    root->left=Create(pi);
    root->right=Create(pi);
    return root;
}

void Inorder(struct BTNode* root)
{
    if(root==NULL)
        return;
    Inorder(root->left);
    printf("%c ",root->c);
    Inorder(root->right);
}

int main()
{
    scanf("%s",str);
    int i=0;
    struct BTNode* root=Create(&i);
    Inorder(root);
    return 0;
}

#我的实习求职记录#
全部评论

相关推荐

这一生如履薄冰:产品经理现在都要会微调大模型了吗
点赞 评论 收藏
分享
08-01 11:19
电气工程师
我懒羊羊觉得没问题:写的太学生化了,像作文一样,很难看出你和岗位的匹配度
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务