#include <stdio.h>
#include <stdlib.h>
typedef  struct root
{
    struct root* left;
    struct root* right;
    char val;
}root;
//中序遍历二叉树
void root_parent(root* root1)
{
    if (root1 == NULL) 
    {
        return;
    }
    root_parent(root1->left);
    printf("%c ",root1->val);
    root_parent(root1->right);
}
//前序创建二叉树
root* root_malloc(char* a,int* pi)
{
    if (a[*pi] == '#') 
    {
        (*pi)++;
        return NULL;
    }
    root* newnode=(root*)malloc(sizeof(root));
    newnode->val=a[(*pi)++];
    newnode->left = root_malloc(a,pi);
    newnode->right = root_malloc(a,pi);
    return newnode;
}
int main()
{
    char arr[100];
    scanf("%s",arr);
    int i=0;
    root* ret = root_malloc(arr,&i);
    root_parent(ret);
    return 0;
}

解析我放这里,点击链接直接观看

https://blog.csdn.net/Jason_from_China/article/details/139239367