-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.c
More file actions
65 lines (50 loc) · 1.44 KB
/
Copy pathtests.c
File metadata and controls
65 lines (50 loc) · 1.44 KB
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
#include <stdio.h>
#include <stdlib.h>
#include "treedefinitions.c"
#include "traversal.c"
// main
int main() {
node *tree = NULL;
insert(3, &tree);
printf("%i\n", tree->n);
insert(4, &tree);
insert(1, &tree);
insert(6, &tree);
insert(2, &tree);
insert(0, &tree);
insert(9, &tree);
insert(5, &tree);
pretrav(tree);
printf("\n");
intrav(tree);
printf("\n");
posttrav(tree);
printf("\n");
leveltrav(tree);
printf("\n");
printf("%i\n", search(3, tree));
printf("%i\n", search(1, tree));
printf("%i\n", search(0, tree));
printf("%i\n", search(9, tree));
printf("%i\n", height(tree));
delet(5, &tree);
delet(1, &tree);
leveltrav(tree);
printf("\n");
delet(3, &tree);
printf("%i\n", tree->n);
leveltrav(tree);
printf("\n");
printf("%i\n", height(tree));
freetree(tree);
// attempting to print should return garbage value
printf("%i\n", tree->n);
/**
* Note: tree should be set to NULL here, either following memory clearance in the
* function or in main, otherwise it will retain its pointer to a random location
* in memory. In a large program, if this pointer were reaccessed, it could corrupt
* data if the location had since been written to by another part of the program
* (setting to NULL throws location away).
*/
return 0;
}