碱性洗发水有哪些品牌:怎样用“双亲孩子”法构造一个二叉树

来源:百度文库 编辑:中科新闻网 时间:2024/03/29 22:57:36
也就是用二叉链表

#include<stdio.h>
#include<malloc.h>
typedef struct Node{
char data;
struct Node *Lchild,*Rchild;
}*TNode;
/*输入二叉数时,按先根遍历输入*/
void CreatTree(TNode* T)
{
char ch;
printf("input: ");
scanf("%c",&ch);
getchar();/*接收回车的*/
if(ch==' ')
{
(*T)=NULL;
}
else
{
if(!((*T)=(struct Node*)malloc(sizeof(struct Node))))
{
(*T)->Lchild=NULL;
(*T)->Rchild=NULL;
(*T)->data=ch;
}
CreatTree( &((*T)->Lchild));
CreatTree( &((*T)->Rchild));
}
}
void main()
{
TNode T;
T=NULL;

CreatTree(&T);
printf("ff");
}