简单二叉树
作者:互联网
#include"stdio.h" #include"stdlib.h" typedef struct node{ struct node *lchild; int data; struct node *rchild; }NODE; NODE * chushi(NODE *s) { s->data=1; s->lchild=s->rchild=NULL; return s; } NODE *creat(NODE *s,char f,int x) { NODE *m; m=(NODE *)malloc(sizeof(NODE)); m->data=x; if(f=='l') s->lchild=m; if(f=='r') s->rchild=m; m->lchild=m->rchild=NULL; return s; } void digui(NODE * T) { if(T!=NULL) { printf("%d\n",T->data); digui(T->lchild); digui(T->rchild); }} main() { NODE *s=(NODE *)malloc(sizeof(NODE)); NODE *p,*l,*r; s=chushi(s); p=s; p=creat(p,'l',2); p=creat(p,'r',5); l=p->lchild; r=p->rchild; l=creat(l,'l',3); l=creat(l,'r',4); r=creat(r,'l',6); r=creat(r,'r',7); digui(s); }
标签:NODE,lchild,creat,digui,二叉树,简单,rchild,data 来源: https://www.cnblogs.com/yjx20010111959/p/11007520.html