-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.c
47 lines (38 loc) · 975 Bytes
/
example.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
#include <stdio.h>
#include <stdlib.h>
#include "./record.h"
#include "./bt/bt.h"
#include "./bt/bt_io.h"
#include "./bt/bst/bst.h"
int main(int argc, char const *argv[]) {
// nodes defining a tree
// value, parent_index
int eg_nodes[][3] = {
{2, -1},
{5, 0},
{7, 1},
{33, 2},
{19, 0},
{8, 4},
{9, 4},
{11, 6},
{14, 6}
};
// convert 2D array to pointer to pointers
int eg_nodes_count = sizeof(eg_nodes) / sizeof(*eg_nodes);
int **eg_pointer = malloc(eg_nodes_count * sizeof(&eg_nodes));
for (int i = 0; i < eg_nodes_count; i++) {
eg_pointer[i] = eg_nodes[i];
}
// convert to tree
B_Tree *u = BT_readInts(eg_pointer, eg_nodes_count, *NAT_recordsCompare1);
// print tree
printf("\n");
BT_print2D(u);
printf("\n");
BT_printFlat(u);
// free up everything
free(eg_pointer);
BT_freeTree(u);
return 0;
}