我剛好有個擴充套件先序輸入,然後凹入法輸出的原始碼,你改改就行了:
#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);
}