forked from aed-i-2024-q1/aula-10-11-abb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
101 lines (76 loc) · 1.86 KB
/
main.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
#include <stdio.h>
#include "bst.h"
// TODO: Call destructor when it is implemented
void testSearch() {
BST* bst = bst_create();
Element contains[] = {50, 43, 3, 48, 61, 58, 70};
Element notContains[] = {0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 90, 100};
for (int i = 0; i < 8; i++) {
printf("%d: %sfound\n", contains[i], bst_search(bst, contains[i]) ? "" : "not ");
}
for (int i = 0; i < 12; i++) {
printf("%d: %sfound\n", notContains[i], bst_search(bst, notContains[i]) ? "" : "not ");
}
bst_destroy(bst);
}
void testTraversals() {
BST* bst = bst_create();
printf("InOrder: ");
bst_printInOrder(bst);
printf("PreOrder: ");
bst_printPreOrder(bst);
printf("PostOrder: ");
bst_printPostOrder(bst);
printf("\n");
bst_destroy(bst);
}
void testInsert() {
BST* bst = bst_create();
bst_insert(bst, 50);
bst_insert(bst, 43);
bst_insert(bst, 3);
bst_insert(bst, 48);
bst_insert(bst, 61);
bst_insert(bst, 58);
bst_insert(bst, 70);
bst_print(bst);
bst_destroy(bst);
}
void testPrint() {
BST* bst = bst_create();
bst_print(bst);
bst_destroy(bst);
}
void testRemove() {
BST* bst = bst_create();
Element elements[] = {50, 43, 3, 48, 61, 58, 70};
for (int i = 0; i < 7; i++) {
bst_insert(bst, elements[i]);
}
bst_print(bst);
printf("\n");
bst_remove(bst, 3);
bst_print(bst);
printf("\n");
bst_remove(bst, 43);
bst_print(bst);
printf("\n");
bst_remove(bst, 61);
bst_print(bst);
printf("\n");
// bst_remove(bst, 48);
// bst_print(bst);
// printf("\n");
// bst_remove(bst, 50);
// bst_print(bst);
// printf("\n");
bst_destroy(bst);
}
int main() {
// testSearch();
// testTraversals();
// testPrint();
// testInsert();
testRemove();
return 0;
}