aboutsummaryrefslogtreecommitdiff
path: root/examples/tree.c
blob: e55acb900b860bc06d54ae711ef17868ca1f1a0b (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
#include <bowl.h>

int main()
{
    err_t e;

    // Initialise a root node
    struct bowl *root;
    e = bowl_malloc(&root, ARRAY);
    if(e) return e;

    // First Node
    struct bowl *a;
    e = data_malloc(&a, LITERAL, "Destroy capitalism");
    if(e) return e;

    // Second Node
    struct bowl *b;
    e = data_malloc(&b, INTEGER, 1312);
    if(e) return e;

    // Third node is another ARRAY
    struct bowl *c;
    e = bowl_malloc(&c, ARRAY);
    if(e) return e;

    // Fourth node is another string
    struct bowl *d;
    e = data_malloc(&d, LITERAL, "Alerta, Antifascista!");
    if(e) return e;

    // Add the d node to c
    e = bowl_insert(c, d);
    if(e) e;

    // Add other nodes to root
    e = bowl_insert(root, a);
    if(e) return e;
    e = bowl_insert(root, b);
    if(e) return e;
    e = bowl_insert(root, c);
    if(e) return e;

    e = bowl_free(root);
    return e;
}