tree

来源:互联网 发布:python 列表复制 编辑:程序博客网 时间:2024/05/18 01:01

这是一个二叉树的打印代码
编译成功,但运行崩溃
求解

#include<stdio.h>#define null 0struct tree{  char  data;  tree  * lchild;  tree  * rchild;};void trav(tree  * p)     {    if(p->data!= null)    {        printf("\t%c\n",p->data);          trav(p->lchild);          trav(p->rchild);    }}main(){  tree  t1,t2,t3,t4,t5,t6,t7;  t1.data='A';  t1.lchild=&t2;  t1.rchild=&t3;  t2.data='B';  t2.lchild=&t4;  t2.rchild=&t5;  t3.data='C';  t3.lchild=&t6;  t3.rchild=&t7;  t4.data='D';  t4.lchild=null;  t4.rchild=null;  t5.data='E';  t5.lchild=null;  t5.rchild=null;  t6.data='F';  t6.lchild=null;  t6.rchild=null;  t7.data='G';  t7.lchild=null;  t7.rchild=null;  trav(&t1); }

“`

原创粉丝点击