作者在 2010-05-12 21:24:22 发布以下内容
#include<stdio.h>
typedef char Datatype;
typedef struct BiTNode {
Datatype data;
struct BiTNode *lchild, *rchild;
} BiTNode, *BiTree;
void CreateBiTree(BiTree *T)
{
char ch;
scanf("%c",&ch);
if(ch=='#')
(*T)=NULL;
else
{
(*T)=(BiTree)malloc(sizeof(BiTNode));
if(!(*T))
exit(0);
(*T)->data=ch;
CreateBiTree(&(*T)->lchild);
CreateBiTree(&(*T)->rchild);
}
}
void Print_bitree(BiTree *T,int Layer)
{/**//*按竖向树状打印的二叉树*/
int i;
if(*T==NULL)
return;
Print_bitree(&(*T)->rchild,Layer+1);
for(i=0;i<Layer;i++)
printf(" ");
printf("%c\n",(*T)->data); /*按逆中序输出结点,用层深决定结点的左右位置*/
Print_bitree(&(*T)->lchild,Layer+1);
}
void main()
{
int Layer;
BiTNode* S;
Layer=0;
printf("Enter the char:\n");
CreateBiTree(&S);
printf("Output the bitree:\n");
Print_bitree(&S,Layer);
}
typedef char Datatype;
typedef struct BiTNode {
Datatype data;
struct BiTNode *lchild, *rchild;
} BiTNode, *BiTree;
void CreateBiTree(BiTree *T)
{
char ch;
scanf("%c",&ch);
if(ch=='#')
(*T)=NULL;
else
{
(*T)=(BiTree)malloc(sizeof(BiTNode));
if(!(*T))
exit(0);
(*T)->data=ch;
CreateBiTree(&(*T)->lchild);
CreateBiTree(&(*T)->rchild);
}
}
void Print_bitree(BiTree *T,int Layer)
{/**//*按竖向树状打印的二叉树*/
int i;
if(*T==NULL)
return;
Print_bitree(&(*T)->rchild,Layer+1);
for(i=0;i<Layer;i++)
printf(" ");
printf("%c\n",(*T)->data); /*按逆中序输出结点,用层深决定结点的左右位置*/
Print_bitree(&(*T)->lchild,Layer+1);
}
void main()
{
int Layer;
BiTNode* S;
Layer=0;
printf("Enter the char:\n");
CreateBiTree(&S);
printf("Output the bitree:\n");
Print_bitree(&S,Layer);
}