It was so hard, but finally, I got it written.
Firstly, pay attention to, what he needs to string. It needs to be assigned, and we need to use recursion to assign it. and we need to create a main function,let's have a look at the code.
#include<stdio.h>
#include<stdlib.h>
typedef struct BTNode {
char val;//note that this is a string
struct BTNode* right;
struct BTNode* left;
}BTNode;
BTNode* Creat(char* a, int* pi)
{
if (a[*pi] == '#')
{
(*pi)++;
return NULL;
}
BTNode* root = (BTNode*)malloc(sizeof(BTNode));
root->val = a[(*pi)++];
root->left = Creat(a, pi);
root->right = Creat(a, pi);
return root;
}
void Inorder(BTNode* root)
{
if (root)
{
Inorder(root->left);
printf("%c ", root->val);
Inorder(root->right);
}
}
int main()
{
char a[101];
scanf("%s", a);
int count=0;
BTNode* root = Creat(a, &count);
Inorder(root);
return 0;
}