题解 | #二叉树遍历#

二叉树遍历

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

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

typedef struct BinTree
{
    struct BinTree*left;
    struct BinTree*right;
    char val;
}BT;

BT* Creater_Tree(char* buff,int* pi)//递归构建二叉树
{
    if(buff[*pi]=='#')
    {
        (*pi)++;
        return NULL;
    }
    BT*Treenode = (BT*)malloc(sizeof(BT));
    Treenode->val = buff[(*pi)++];
    Treenode->left = Creater_Tree(buff,pi);
    Treenode->right = Creater_Tree(buff,pi);
    return Treenode;
}
void In_Post(BT*root)
{
    if(root==NULL)
        return;
    In_Post(root->left);
    printf("%c ",root->val);
    In_Post(root->right);
}
int main()
{
    int i = 0;
    char str[100];
    scanf("%s",str);
    BT*root = Creater_Tree(str,&i);
    In_Post(root);
    return 0;
}

#刷题#
全部评论

相关推荐

11-01 08:48
门头沟学院 C++
伤心的候选人在吵架:佬你不要的,能不能拿户口本证明过户给我。。球球了
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务