back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/rb_tree.h
blob: 491e5b837118388f20219cf0f616a2ad07a6565e (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
#ifndef RB_TREE_H_SENTRY
#define RB_TREE_H_SENTRY

enum color_type { red, black };

struct node_type {
    int key;
    enum color_type color;
    struct node_type *p;
    struct node_type *left;
    struct node_type *right;
};
typedef struct node_type node;

struct rb_tree_type {
    node *root;
    node *nil;
};
typedef struct rb_tree_type rb_tree;

void rb_tree_init(rb_tree *t);
void rb_tree_insert_node(rb_tree *t, node *cur_node);
void rb_tree_delete_node(rb_tree *t, node *cur_node);
void rb_tree_clear(rb_tree *t, node *root);
node* rb_tree_create_node(rb_tree *t, int num);
node* rb_tree_search(rb_tree *t, node *root, int num);
void rb_tree_print(rb_tree *t, node *root);

#endif