1 #ifndef __HEAD_H__
2 #define __HEAD_H__
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 typedef char dataType;
7 typedef struct Tree
8 {
9 dataType data;
10 struct Tree* lchild;
11 struct Tree* rchild;
12 } Seq;
13 Seq* creat_binaryTree();
14 void show_preo(Seq *root);
15 void show_Inorder(Seq *root);
16 void show_post(Seq *root);
17 #endif
18
19 #include "03_head.h"
20
21 Seq* creat_binaryTree()
22 {
23 char value = 0;
24 scanf("%c",&value);
25 getchar();
26 if('#' == value)
27 {
28 return NULL;
29 }
30 Seq* root = (Seq*)malloc(sizeof(Seq));
31 if(NULL == root)
32 {
33 printf("创建失败\n");
34 return NULL;
35 }
36 root->data = value;
37 root->lchild = creat_binaryTree();
38 root->rchild = creat_binaryTree();
39 return root;
40 }
41 void show_preo(Seq *root)
42 {
43 if(root != NULL)
44 {
45 printf("%c",root->data);
46 show_preo(root->lchild);
47 show_preo(root->rchild);
48 }
49 return;
50 }
51 void show_Inorder(Seq *root)
52 {
53 if(NULL == root)
54 {
55 return;
56 }
57 show_Inorder(root->lchild);
58 printf("%c",root->data);
59 show_Inorder(root->rchild);
60
61 return;
62 }
63 void show_post(Seq *root)
64 {
65 if(NULL == root)
66 {
67 return;
68 }
69 show_post(root->lchild);
70 show_post(root->rchild);
71 printf("%c",root->data);
72 return;
73 }
74
75 #include "03_head.h"
76 int main(int argc, const char *argv[])
77 {
78 Seq *binTree = creat_binaryTree();
79 show_preo(binTree);
80 putchar(10);
81 show_Inorder(binTree);
82 putchar(10);
83 show_post(binTree);
84 putchar(10);
85 return 0;
86 }