Skip to content

dzourn/red-black-tree-generic-C

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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);

About

Generic Data Type - Red Black Tree implementation in C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages