-
Notifications
You must be signed in to change notification settings - Fork 0
/
树.c
107 lines (106 loc) · 2.73 KB
/
树.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "BinTree.h"
#include "Queue.h"
#include <stdlib.h>
#include <stdio.h>
#include "AVLTree.h"
int mainTree(){
int i;
BinTree * tree = initBinTree();
if(tree->size == 0){
/*
insertAsRoot(tree,16);
insertAsLC(10,root(tree));
insertAsRC(25,root(tree));
insertAsLC(19,root(tree)->rc);
insertAsRC(28,root(tree)->rc);
insertAsLC(5,root(tree)->lc);
insertAsRC(11,root(tree)->lc);
//insertNode(tree,3);
*/
/*insertNode(tree,16);
insertNode(tree,10);
insertNode(tree,25);
insertNode(tree,19);
insertNode(tree,28);
insertNode(tree,5);
insertNode(tree,11);
insertNode(tree,4);
insertNode(tree,33);
insertNodeAVL(36,tree);
insertNodeAVL(38,tree);
insertNodeAVL(39,tree);
insertNodeAVL(40,tree);
insertNodeAVL(41,tree);
*/
/*
insertNodeAVL(3,tree);
insertNodeAVL(5,tree);
insertNodeAVL(11,tree);
insertNodeAVL(16,tree);
insertNodeAVL(19,tree);
insertNodeAVL(25,tree);
insertNodeAVL(28,tree);
insertNodeAVL(33,tree);
insertNodeAVL(36,tree);
insertNodeAVL(39,tree);
insertNodeAVL(41,tree);
insertNodeAVL(43,tree);
deleteBinNode(tree,28);
deleteBinNode(tree,5);
deleteBinNode(tree,25);
deleteBinNode(tree,3);
deleteBinNode(tree,33); */
for(i = 1 ; i < 10 ; i++){
insertNodeAVL(i,tree);
}
}
if(tree->size!=0){
printf("根节点:%d \n" , root(tree)->data);
printf("高度: %d\n",get_tree_height(root(tree)));
printf("\n中序遍历---------------\n");
travIn_R(root(tree));
//printf("\n %d ",searchIn(root(tree),11)->data);
//printf("\n %d ", getMax(root(tree))->data);
//printf("\n %d ", getMin(root(tree))->data);
printf("\n");
}
for(i = 1 ;i < 8 ; i++)
deleteBinNode(tree,i);
//deleteNodeAVL(tree , i);
if(tree->size!=0){
printf("根节点:%d \n" , root(tree)->data);
printf("高度: %d\n",get_tree_height(root(tree)));
printf("\n中序遍历---------------\n");
travIn_R(root(tree));
}
/*
if(tree->size == 0){
insertAsRoot(tree,'A');
insertAsLC('B',root(tree));
insertAsRC('E',root(tree));
insertAsRC('G',root(tree)->rc);
insertAsLC('F',root(tree)->rc);
insertAsLC('C',root(tree)->lc);
insertAsRC('D',root(tree)->lc);
}
if(tree->size!=0){
printf("高度: %d\n",getTreeHeight(tree));
printf("高度: %d\n",get_tree_height(root(tree)));
printf("节点数目:%d\n",getBinNodeSize(root(tree)));
printf("前序遍历---------------\n");
travPre(root(tree));
printf("\n");
travPre_I1(root(tree));
printf("\n");
travPre_I2(root(tree));
printf("\n中序遍历---------------\n");
travIn_R(root(tree));
printf("\n");
travIn_I1(root(tree));
printf("\n层次遍历---------------\n");
traveLevel(root(tree));
printf("\n叶子节点数目 %d \n ",getLeafNum(root(tree)));
//printf("\n%c",search(root(tree),'C')->data);
} */
return 0;
}