📄 n4.c
字号:
#include"stdio.h"
#define MAX 100
typedef struct tnode
{
char data;
struct tnode * ichild, * rchild;
}TNODE;
TNODE * create();
TNODE * create()
{
TNODE * root;
char s[4*MAX];
gets(s);
setup(s,&root);
printtree(root);
return(root);
}
int index=0;
setup(s,ptr)
char s[];
TNODE * *ptr;
{
TNODE * p;
if(s[index]=='\0') return;
else if(s[index]!='\0')
{p=(TNODE*) malloc(sizeof(TNODE));
p->data=s[index];
p->ichild=p->rchild=NULL;
*ptr=p;
index ++;
setup(s,&(p->ichild));
index ++;
setup(s,&(p->rchild));
}
else
index ++;
return;
}
printtree(ptr)
TNODE * ptr;
{
if(ptr==NULL) return;
printf("\nstructure of the binary tree:\n");
printf("number\taddress\tichild\tdata\trchild\n");
printforder(ptr);
}
int num=0;
printorder(ptr)
TNODE * ptr;
{
if(ptr==NULL) return;
printf("%d\t%u\t%u\t\%c\t%u\n",++num,ptr,ptr->ichild,ptr->data,ptr->rchild);
if(ptr->ichild!=NULL) printorder(ptr->ichild);
if(ptr->rchild!=NULL) printorder(ptr->rchild);
}
main()
{
TNODE * root;
root=creat();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -