Skip to content

Latest commit

 

History

History
38 lines (33 loc) · 819 Bytes

README.md

File metadata and controls

38 lines (33 loc) · 819 Bytes

red-black-tree-generic-C

Generic Data Type - Red Black Tree implementation in C
Chapter 14 (Red Black Trees), Introduction to Algorithms, Second edition by Cormen, Leiserson, Rivest, Stein

How to use

  1. Your compare function must return an interger
int mycmpr(void* a, void* b)

if mycmpr(...)<0 then a is less than b
if mycmpr(...)=0 then a is equal to b
if mycmpr(...)>0 then a is greater than b

  1. Initialize your red black tree with:
rbt_tree* tree = rbt_tree rbt_init(mycmpr)
  1. Enter data (ex intergers)
int y = 1;
rbt_node* new = rbt_newNode(&y, sizeof(int));
rbt_insert(tree, new);  

you can also do:

rbt_insert(tree, rbt_newNode(&y, sizeof(int));
  1. Delete data (if needed)
rbt_delete(t, new);
  1. Free allocated memory
rbt_free(tree);