-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitree.c
61 lines (49 loc) · 1011 Bytes
/
bitree.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef char TElemType;
typedef int Status;
typedef struct BiTNode{
TElemType data;
struct BiTNode *lchild, *rchild;
}BiTNode, *BiTree;
BiTree CreateBiTree(BiTree *T) //ÏÈÐòÐòÁд´Ôì¶þ²æÊ÷
{
char ch;
scanf("%c", &ch);
getchar();
if(ch == '#')
*T = NULL;
else
{
if( !(*T = (BiTNode *)malloc(sizeof(BiTNode))))
exit(1);
(*T)->data = ch;
CreateBiTree(&((*T)->lchild));
CreateBiTree(&((*T)->rchild));
}
return NULL;
}
Status visit(TElemType e)
{
printf("%c ", e);
return 0;
}
Status InOrderTraverse(BiTree T, Status (*visit)(TElemType e))
{
if(T != NULL)
{
InOrderTraverse(T->lchild, visit);
visit(T->data);
InOrderTraverse(T->rchild, visit);
}
return 0;
}
int main(int argc, char *argv)
{
//BiTNode root;
BiTree T;// = &root;
CreateBiTree(&T);
InOrderTraverse(T, visit);
return 0;
}