#include<stdio.h>
#include<stdlib.h>
#define SIZE sizeof(struct tree)
int i=1;
struct tree
{
char data;
struct tree *lchild,*rchild;
};
int creattree(struct tree**);
int printtree(struct tree **);
int main(void)
{
struct tree*T;
struct tree**p=&T;
creattree(p);
printtree(p);
return 0;
}
int creattree(struct tree**p)
{
char *ch;
ch=(char*)malloc(1);
if(ch==NULL)
return -1;
printf("ÇëÊäÈëch:\n");
scanf("%c",ch);
getchar();
if(*ch=='#')
{
*p=NULL;
}
else
{
*p=(struct tree*)malloc(SIZE);
(*p)->data=*ch;
creattree(&((*p)->lchild));
creattree(&((*p)->rchild));
}
free(ch);
return 0;
}
int printtree(struct tree**r)
{
if(*r!=NULL)
{
printf("%c\n",(*r)->data);
printtree(&((*r)->lchild));
printtree(&((*r)->rchild));
}
return 0;
}
26补空法二叉链表
最新推荐文章于 2024-09-06 14:55:54 发布