数据结构二叉树问题

C语言下的数据结构作业:1) 选择以下一种方式建立二叉树。
根据前序遍历序列创建二叉树:例如用户输入:ABDECF#,(2) 查找给定的结点,如B;
(3) 打印输出二叉树*(选择一种遍历算法实现)
本人先写了一点,但后面实在不知道如何写了,希望大家帮忙,希望完整的可运行的程序代码最好附有注释,答的好再加分,谢谢大家了
我的部分代码
#include <stdio.h>
#include <stdlib.h>
typedef struct BTree{
char data;
struct BTree *lchild;
struct BTree *rchild;
}BinTree;
BinTree *pre_order()
{
BinTree *p;
char ch;
scanf("%c",&ch);
if(ch==' ')
return NULL;
p=(BinTree *)malloc(sizeof(BinTree));
p->data=ch;
p->lchild=pre_order();
p->rchild=pre_order();
return p;
}
BiTree search_tree(BiTree T,int keyword,BiTree *father)
{
BiTree p;
p*father = NULL;
p = T;
while (p && p->data!=keyword)
{*father = p;
if (keyword < p->data)
p = p->lchild;
else p = p->rchild;
}
return p;
}
void main()
{
}

#include<stdio.h>
#include<stdlib.h>
typedef struct node *tree_pointer;
struct node{
char ch;
tree_pointer left_child,right_child;
};
tree_pointer root=NULL;
tree_pointer create(tree_pointer ptr)
{
char ch;
scanf("%c",&ch);
if(ch==' ')
ptr=NULL;
else{
ptr=(tree_pointer)malloc(sizeof(node));
ptr->ch=ch;
ptr->left_child=create(ptr->left_child);
ptr->right_child=create(ptr->right_child);
}
return ptr;
}
void inorder(tree_pointer ptr)
{
if(ptr){
inorder(ptr->left_child);
printf("%c",ptr->ch);
inorder(ptr->right_child);
}
}
int search(tree_pointer ptr,char ch,int h)
{
int flag=0;
if(!ptr)
return 0;
if(ptr->ch==ch)
return h;
else{
flag=search(ptr->left_child,ch,h+1);
if(!flag)
flag=search(ptr->right_child,ch,h+1);
return flag;
}
}
void main()
{
char ch='A';
/*printf("输入所要查找的元素:\n");
scanf("%c",&ch);*/
printf("构建一个二叉树:\n");
root=create(root);
if(!search(root,ch,1))
printf("所要查找的元素%c不在二叉树中\n",ch);
else
printf("所要查找的元素%c在二叉树的第%d层\n",ch,search(root,ch,1));
printf("中序遍历二叉树:\n");
inorder(root);
}
温馨提示:答案为网友推荐,仅供参考