自己试了几组数据没发现问题,上传以后只有两个AC,其他是WA,求大佬帮我看下是那里的问题
#include <stdio.h>
#include <stdlib.h>
struct node{
char data;
struct node* left;
struct node* right;
};
struct node* root=0;
void insert (char x[]);
struct node* newnode (char x);
void preorder (struct node* r);
void pre (struct node* r,char x[]);
int main()
{
int n=0;
int i=0;
char x[3];
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%s",x);
insert(x);
}
preorder(root);
return 0;
}
void insert (char x[])
{
struct node* r=0;
r=root;
if(r==0){
root=newnode(x[0]);
root->left=newnode(x[1]);
root->right=newnode(x[2]);
}else{
pre(root,x);
}
}
struct node* newnode (char x)
{
struct node* t=(struct node*)malloc(sizeof(struct node));
if(x=='*'){
return 0;
}
t->data=x;
t->left=0;
t->right=0;
return t;
}
void preorder (struct node* r)
{
if(r==0){
return;
}
printf("%c",r->data);
preorder(r->left);
preorder(r->right);
}
void pre (struct node* r,char x[])
{
if(r==0){
return;
}
if(r->data==x[0]){
r->left=newnode(x[1]);
r->right=newnode(x[2]);
return;
}
pre(r->left,x);
pre(r->right,x);
}