/*我是用先序建立二叉树得到二叉树图象,在遍历二叉树输出非空结点的值,但好象有问题,
反复做了两天了还是没找到,请各位兄弟帮忙看一下,问题是在哪里,谢谢!*/
谢谢各位!!!!
#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<alloc.h>
#define NULL 0
struct node{                  /*结点的数据结构*/
char data;
int x;                        /*结点所在的坐标x,y*/
int y;
struct node *lchild,*rchild;
}*t,*p;                       /*定义两个结点*/
int i=10,n=0;
int x,y;                      /*这里的x,y是为了以后遍历时输到屏幕上,这里不用*/
char *ch;
char temp;
struct node * CreatBitree(struct node *,int,int,int,int);/*先序创建二叉树声明*/
struct node * pre_trav(struct node *);      /*先序遍历并输出结点的字符*/

main()               
{
  int drive,mode;                     /*初试化图形*/
  drive=DETECT;
  mode=0;
 initgraph(&drive,&mode,"");
 setcolor(BLUE);
 p=CreatBitree(t,200,100,200,100);  /*创建一棵树,p指向树的根t*/
 outtextxy(100,450,"The order is:");
 x=160;y=450;
 pre_trav(p);                      /*先续遍历树*/
 getch();
 getch();
 cleardevice();
 closegraph();
}           
                                  /*end main() */
struct node * CreatBitree(struct node *T,int fx,int fy,int prex,int prey){
scanf("%c",ch); temp=*ch; /*输入一个创建一个结点;fx,fy,prex,prey是为了画结点间的直线*/   
if(temp=='#') T=NULL;     /*如果输入#则为空结点*/
 else{                    /*否则创建一个结点*/
   T=(struct node *)malloc(sizeof(struct node));
   if(!T) exit(0);
  T->data=temp;
  T->x=fx;T->y=fy;
  circle(fx,fy,i);
  line(prex,prey,fx,fy);
  setcolor(RED);                 /*把输出的结点字符变红*/
  outtextxy(fx-4,fy-4,ch);       /*输出结点字符*/
  setcolor(BLUE);                               
  CreatBitree(T->lchild,fx-30,fy+30,fx,fy); /*递归创建左孩子结点*/
  CreatBitree(T->rchild,fx+30,fy+30,fx,fy); /*递归创建右孩子结点*/
 }
 return T;
}

struct node * pre_trav(struct node *q) /*先序遍历并输出结点的字符*/
{/*outtextxy(x,y,&(q->data));  /*把非空结点值输出到屏幕,这里没用,用的是prinetf输出*/
  x=x+12;*/
 if(q!=NULL)
 { printf("%c",q->data);
  x=x+10;
  pre_trav(q->lchild);
  pre_trav(q->rchild);
  return q;
  }
  else return q;
}

/*我输入abc####(也可以输入其他字符先序序列)先序创建二叉树得到二叉树的图象,
但再遍历二叉树只得到第一个结点的值a,其他的看不到,不知道是为什么,我用的是
TC2.0编译。请各位兄弟帮忙看一下,问题是在哪里,谢谢各位!!!!*/