-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample_binary_tree.c
More file actions
49 lines (40 loc) · 887 Bytes
/
example_binary_tree.c
File metadata and controls
49 lines (40 loc) · 887 Bytes
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
/*
* Author : wqw
* Date : 2018/9/4
* File : Binary_tree.h
* Description : 二叉树的基本功能的测试代码
* e-mail : AuthorityWu@outlook.com
*/
#include <time.h>
#include "binary_tree.h"
int num[15];
// 生成一颗随机二叉树
Tree CreateTree(Tree tree) {
int i;
srand((int)time(NULL));
for (i = 0; i < 15; i++) {
num[i] = rand() % 1000;
tree = NewNode(num[i], tree);
}
return tree;
}
int main() {
Tree tree = NULL;
int i=0;
tree = CreateTree(tree);
Print(tree);
printf("\n");
for (; i < 15; i++) {
printf("Delete: %d \nTree: ", num[i]);
tree = DelNode(num[i], tree);
Print(tree);
printf("\n");
}
tree = CreateTree(tree);
Print(tree);
printf("\n");
tree = MakeEmpty(tree);
Print(tree);
printf("\n");
return 0;
}