Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22117

Simple Struct definition in C for Red Black Tree

$
0
0

I don't use the C language since years and now I need it again. I'm trying to build a Red-Black Tree but I'm stuck at the beginning because I'm missing something about "structs".

Take a look to my "structs" declarations please, they are easy. This is a header file included in Red_black_tree.c

 #define BLACK 0 //defalut color
#define RED 1 //

struct Node {  //create a black node by default, to have a red one look at "create_red_node"
    struct Node *left = NULL;
    struct Node *right= NULL;
    int key = 0;
    int value = 0;
    char color = BLACK;
};

struct Root_t {
    struct Node* Root;
};

struct Node* create_node () {
    struct Node* black = (Node*) malloc (sizeof(Node));
    return black;
}

struct Node* create_red_node () {
    struct Node* red = create_node ();
    red->color=RED;
    return red;
}

Root_t* create_tree () {
    struct Root_t* fake=(Root_t*) malloc (sizeof(Root_t));
    struct fake->Root->left=create_red_node ();
    struct fake->Root->right=create_red_node ();
    return fake;
}

I compiled with "gcc Red_black_tree.c -o RBTree". GCC says something like : "expected ';' at end of declaration list" 7 times, or "must use 'struct' tag to refer to type... ", "expected identifier...". What do you think, is it good to create RBTree?


Viewing all articles
Browse latest Browse all 22117

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>