凹入法打印二叉树
凹入法打印二叉树,大虾们帮帮忙啊,急用!
#include <stdio.h>
#include <stdlib.h>
#define LEN sizeof(struct BiTreeLnode)
typedef struct BiTreeLnode
{
char data;
struct BiTreeLnode *lchild, *rchild;
}* BiTree;
//pre
void Creat_BiTree( BiTree &T )
{
char string[5];
scanf("%s", string);
if( string[0] == '*')
T = NULL;
else
{
if(!(T=( BiTree) malloc (LEN)))
exit(0);
T->data = string[0];
Creat_BiTree( T->lchild );
Creat_BiTree( T->rchild );
}
}
void Preoder_BiTree( BiTree T, int i )
{
if(T)
{
int j;
for( j=i; j>0; j--)
printf(" ");
printf("%c\n", T->data);
Preoder_BiTree( T->lchild, i+1 );
Preoder_BiTree( T->rchild, i+1 );
}
}
int main()
{
BiTree T;
Creat_BiTree( T );
Preoder_BiTree( T, 0 );
return 0;
}