CH5_4.C
上传用户:lgb298
上传日期:2013-03-22
资源大小:1025k
文件大小:1k
- #include <alloc.h>
- #include <stdio.h>
- #define M 20
- typedef struct node
- { char data;
- struct node *lchild,*rchild;
- }JD;
- void inorder(JD *bt)
- { int i=0;
- JD *p,*s[M];
- p=bt;
- do
- { while(p!=NULL)
- { s[i++]=p;
- p=p->lchild;
- }
- if(i>0)
- { p=s[--i];
- printf("%ct",p->data);
- p=p->rchild;
- }
- }while(i>0||p!=NULL);
- }
- JD *crt_bt_pre(JD *bt)
- { char ch;
- printf("ch=");
- scanf("%c",&ch);
- getchar();
- if(ch==' ') bt=NULL;
- else
- { bt=(JD *)malloc(sizeof(JD));
- bt->data=ch;
- bt->lchild=crt_bt_pre(bt->lchild);
- bt->rchild=crt_bt_pre(bt->rchild);
- }
- return(bt);
- }
- void main()
- { JD *head=NULL;
- /* char a[]={'A','B','C',' ',' ','D','E',' ','G',' ',' ','F',' ',' ',' '};*/
- head=crt_bt_pre(head);
- inorder(head);
- }