程序在下面:
就是输入测试数据:ABD000CE00F00;
没什么结果!
大家帮忙看看!
/* Note:Your choice is C IDE */
#include "stdio.h"
#include "malloc.h"
#include "stdlib.h"
typedef struct node
{
char data;
struct node *Lchild,*Rchild;
}BitNode,*BitTree;
void CreateBitTree(BitTree*bt)
{
char ch;
scanf("%c",&ch);
if(ch=='0') *bt=NULL;
else{
(*bt)=( BitNode*)malloc(sizeof(BitNode));
(*bt)->data=ch;
CreateBitTree(&(*bt)->Lchild);
CreateBitTree(&(*bt)->Rchild);
}
}
void Preorder(BitTree q)
{
if(q!=NULL)
{
printf("%c",q->data);
Preorder(q->Lchild);
Preorder(q->Rchild);
}
}
void Inorder(BitTree q)
{
if(q!=NULL)
{
Inorder(q->Lchild);
printf("%c",q->data);
Inorder(q->Rchild);
}
}
void Postorder(BitTree q)
{
if(q!=NULL)
{
Postorder(q->Lchild);
Postorder(q->Rchild);
printf("%c",q->data);
}
}
void PrintTree(BitTree q)
{
if(q!=NULL)
{
printf("%c",q->data);
if(q->Lchild!=NULL||q->Rchild!=NULL)
{
printf("(");
PrintTree(q->Lchild);
if(q->Rchild!=NULL)
printf(",");
PrintTree(q->Rchild);
printf(")");
}
}
}
int Findleft(BitTree q)
{
int count=0;
if(q->Lchild==NULL&&q->Rchild==NULL)
count++;
Findleft(q->Lchild);
Findleft(q->Rchild);
return count;
}
int Findnode(BitTree q)
{
int count=0;
if(q!=NULL)
{
count++;
Findnode(q->Lchild);
Findnode(q->Rchild);
}
return count;
}
void main()
{
int flag=1,choice,leftcount,nodecount;
BitTree T;
while(flag)
{
printf("1------------>´´½¨Ò»¸öÊý\n");
printf("2------------>Ç°Ðò±éÀú\n");
printf("3------------>ÖÐÐò±éÀú\n");
printf("4------------>ºóÐò±éÀú\n");
printf("5------------>Ò¶×Ó½áµãµÄ¸öÊý\n");
printf("6------------>×ܽáµãµÄ¸öÊý\n");
printf("7------------>Í˳ö\n");
printf("ÇëÊäÈëÄãµÄÑ¡Ôñ!\n");
scanf("%d",&choice);
switch(choice)
{
case 1: {printf("input your data!\n");
CreateBitTree(&T);
PrintTree(T);
printf("\n");}
break;
case 2: {Preorder(T);
printf("\n");}
break;
case 3: {Inorder(T);
printf("\n");}
break;
case 4: {Postorder(T);
printf("\n");}
break;
case 5: {leftcount=Findleft(T);
printf("Ò¶×ÓÊýÄ¿ÊÇ£º\n");
printf("%d",leftcount);
printf("\n");}
break;
case 6:{nodecount=Findnode(T);
printf("½áµãÊýÄ¿£º\n");
printf("%d",nodecount);
printf("\n");}
break;
case 7:flag=0;
break;
}
}
}