/
main.c
52 lines (36 loc) · 889 Bytes
/
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
#include <stdlib.h>
#include <stdio.h>
#include "nary_tree.h"
int compare_int(void *a, void *b)
{
int *a_int = (int*) a;
int *b_int = (int*) b;
return (*a_int) == (*b_int);
}
void print_integer(void *a)
{
int *a_int = (int*) a;
printf("%d ", *a_int);
}
int main()
{
nAryTree tree;
int root = 0;
initializeTree(&tree, sizeof(int), &root);
int infoChild = 1;
add_child(&tree, &root, &infoChild, compare_int);
infoChild = 2;
add_child(&tree, &root, &infoChild, compare_int);
infoChild = 3;
add_child(&tree, &root, &infoChild, compare_int);
root = 2;
infoChild = 4;
add_child(&tree, &root, &infoChild, compare_int);
print_pre_order(&tree, print_integer);
printf("\n");
int nodeThatShallBeRemoved = 1;
Node removed;
remove_node(&tree,&nodeThatShallBeRemoved,&removed, compare_int);
print_pre_order(&tree, print_integer);
return 0;
}