
这是一个建立二叉树的程序,但运行时我输完都回车了为什么还要我输入
1个回答
展开全部
我刚好有个扩展先序输入,然后凹入法输出的源码,你改改就行了:
#include "stdio.h"
#include "malloc.h"
typedef struct Node
{
char name;
struct Node *LChild;
struct Node *RChild;
}BiTNode,*BiTree;
void CreateBiTree(BiTree *bt)
{
char ch;
ch=getchar();
if(ch=='.')(*bt)=NULL;
else
{
*bt=(BiTree)malloc(sizeof(BiTNode));
(*bt)->name=ch;
CreateBiTree(&(*bt)->LChild);
CreateBiTree(&(*bt)->RChild);
}
}
void PrintTree( BiTree T, int i )
{
if(T)
{
int j;
for( j=i; j>0; j--)
printf(" ");
printf("%c\n", T->name);
PrintTree( T->LChild, i+1 );
PrintTree( T->RChild, i+1 );
}
}
void main ()
{
BiTree *T;
CreateBiTree(T);
PrintTree(*T,0);
}
#include "stdio.h"
#include "malloc.h"
typedef struct Node
{
char name;
struct Node *LChild;
struct Node *RChild;
}BiTNode,*BiTree;
void CreateBiTree(BiTree *bt)
{
char ch;
ch=getchar();
if(ch=='.')(*bt)=NULL;
else
{
*bt=(BiTree)malloc(sizeof(BiTNode));
(*bt)->name=ch;
CreateBiTree(&(*bt)->LChild);
CreateBiTree(&(*bt)->RChild);
}
}
void PrintTree( BiTree T, int i )
{
if(T)
{
int j;
for( j=i; j>0; j--)
printf(" ");
printf("%c\n", T->name);
PrintTree( T->LChild, i+1 );
PrintTree( T->RChild, i+1 );
}
}
void main ()
{
BiTree *T;
CreateBiTree(T);
PrintTree(*T,0);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询