-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimple_Binary_Tree.c
executable file
·72 lines (63 loc) · 1.33 KB
/
Simple_Binary_Tree.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
62
63
64
65
66
67
68
69
70
71
72
/*
* File Name: Simple_Binary_Tree.c
* Author: sunowsir
* Mail: [email protected]
* Created Time: 2018年10月28日 星期日 15时31分34秒
*/
#include <stdio.h>
#include <stdlib.h>
typedef struct Node {
int data;
struct Node *lchild, *rchild;
} Node;
Node *init(int data) {
Node *root = (Node *)malloc(sizeof(Node));
root->data = data;
root->lchild = NULL;
root->rchild = NULL;
return root;
}
Node *build(/* String, interger, or other data used to create a binary tree. */) {
Node *root = NULL;
/* Call init() to add a node according to requirements. */
return root;
}
void preorder(Node *root) {
if (root == NULL) {
return ;
}
printf("%d ", root->data);
preorder(root->lchild);
preorder(root->rchild);
return ;
}
void inorder(Node *root) {
if (root == NULL) {
return ;
}
inorder(root->lchild);
printf("%d ", root->data);
inorder(root->rchild);
return ;
}
void postorder(Node *root) {
if (root == NULL) {
return ;
}
postorder(root->lchild);
postorder(root->rchild);
printf("%d ", root->data);
return ;
}
int clear(Node *root) {
if (root == NULL) {
return 0;
}
clear(root->lchild);
clear(root->rchild);
free(root);
return 1;
}
int main () {
return 0;
}