blob: 41d96b0a6f0bf96cae3ff0a3eaefc6f1b45cd25f (
plain)
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
|
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "btree.h"
struct b_node *ROOT;
struct b_node* init_node(void)
{
struct b_node* node;
node = malloc(sizeof(struct b_node));
if (!node)
return NULL;
node->key_count = 0;
node->is_leaf = false;
node->keys = NULL;
node->ptrs = NULL;
node->leaf = NULL;
return node;
}
void print_leaf(struct b_node *node)
{
if (!node->is_leaf) {
printf("Error: trying to print a node instead of a leaf\n");
return;
}
/* printf(" Parent node: */
printf("Data: %d\n", node->leaf->data);
printf("Next sib: %p\n", node->leaf->)
void print_root(void)
{
printf("This is the ROOT of the tree \n");
if (ROOT->is_leaf)
print_leaf(ROOT);
else
print_node(ROOT);
}
int main(void) {
ROOT = init_node();
if (!ROOT) {
printf("Error to initialize root node\n");
goto exit0;
}
printf("ROOT: %p\n", ROOT);
free(ROOT);
exit0:
return 0;
}
|