请帮我看看左孩子为什么找不到?
#include<stdio.h>#include<malloc.h>
#define NULL 0
typedef struct BinerTree
{
char data;
struct BinerTree *Lchild,*Rchild,*Parent;
}BT,*BtNode;
void InitataBT(BT **B)
{
(*B)->Lchild = NULL;
(*B)->Rchild = NULL;
(*B)->Parent = NULL;
}
void Creat(BT **B) //用递归来创建树,而节点之间的关系是链接的方式,
{
char ch;
ch = getchar();
if(ch == '.')
*B = NULL;
else
{
if( (*B = (BT *)malloc(sizeof(BT)))==NULL)
{
puts("error memory assignment!");
exit(0);
}
(*B)->data = ch;
Creat(&((*B)->Lchild));
Creat(&((*B)->Rchild));
}
}
void visit(BT *TreeNode)
{
printf("%3c",TreeNode->data);
}
void PreOrder(BT *B)
{
if(B != NULL)
{
visit(B);
PreOrder(B->Lchild);
PreOrder(B->Rchild);
}
}
void InOrder(BT *B)
{
if(B != NULL)
{
InOrder(B->Lchild);
visit(B);
InOrder(B->Rchild);
}
}
void PostOrder(BT *B)
{
if(B != NULL)
{
PostOrder(B->Lchild);
PostOrder(B->Rchild);
visit(B);
}
}
BtNode LeftChild(BT *B,char ch) // 左孩子查找,不过如果没有左孩子这种情况还没有考虑
{
if(B != NULL) //根据创建的结构来进行查询,参考创建部分,因此得出仍然按三种遍历方式来查询?
{
if(B->data == ch)
if(B->Lchild!=NULL)
return B->Lchild;
else return NULL;
LeftChild(B->Lchild,ch);
LeftChild(B->Rchild,ch);
}
return NULL;
}
void main()
{
BT *Btree;
BtNode q;
int OrdSeq;
char node;
InitataBT(&Btree);
Creat(&Btree);
printf("please input 1 to PreOrder the tree:\nplease input 2 to InOrder the tree:\nplease input 3 to PostOrder the tree:\n");
scanf("%d",&OrdSeq);
switch(OrdSeq)
{
case 1: PreOrder(Btree); break;
case 2: InOrder(Btree); break;
case 3: PostOrder(Btree); break;
default :puts("wrong choice!");break;
}
getchar();
puts("\nPlease input the node you are finding:");
scanf("%c",&node);
if( !(q = LeftChild(Btree,node)) )
puts("Sorry!I didn't find the leftchild!\1");
else printf("%5c",q->data);
getch();
}