#include <stdio.h>
#include <malloc.h>
typedef char ElemType;
typedef struct Node
{
ElemType data;
Node *Lchild,*Rchild;
} BiTNode,*BiTree;
BiTree CreateBiTree();//建立二叉树
void PrintTree(BiTree T,int h);//二叉树的横向显示
int main(void)
{
BiTree root=CreateBiTree();
PrintTree(root,1);
return 0;
}
BiTree CreateBiTree()//建立二叉树
{
ElemType x;
BiTree T;
scanf("%c",&x);
if(x=='#')
T=NULL;
else
{
T=(BiTree)malloc(sizeof(BiTNode));
T->data=x;
T->Lchild=CreateBiTree();
T->Rchild=CreateBiTree();
}
return T;
}
void PrintTree(BiTree T,int h)//二叉树的横向显示
{
if(T==NULL)
return;
PrintTree(T->Rchild,h+1);
for(int i=0; i<h; i++)
printf(" ");
printf("%c\n",T->data);
PrintTree(T->Lchild,h+1);
}
二叉树的横向显示
最新推荐文章于 2022-05-06 09:45:40 发布