- 论坛徽章:
- 0
|
下面程序运行后便不终止,错在那里,望高手指点,谢谢先!
- #include "stdio.h"
- #include "stdlib.h"
- #define NULL 0
- typedef struct node
- {
- char data;
- struct node *lchild,*rchild;
- }*TREENODE;
- /*=========*/
- TREENODE CreateTree() //按前序规则建立二叉树
- {
- TREENODE t;
- char c;
- c=getchar();
- getchar();
- printf("%c ",c);
- if(c=='#') return(NULL);
- else
- {
- t=(TREENODE)malloc(sizeof(struct node));
- t->;data=c;
- t->;lchild=CreateTree();
- t->;rchild=CreateTree();
- }
- return(t);
- }
- /*========*/
- void inorder(TREENODE t) //前序遍历二叉树
- {
- TREENODE p;
- p=t;
- if(p)
- {
- inorder(p->;lchild);
- printf("%c ",p->;data);
- inorder(p->;rchild);
- }
- printf("\n");
- }
- /*========*/
- main()
- {
- TREENODE bitree;
- bitree=CreateTree();
- inorder(bitree);
- }
复制代码 |
|