|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
Red Black Trees
From: Brian (bwaichu
yahoo.com)
Date: Mon May 01 2006 - 23:58:07 CDT
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I am reading through the tree(3), and I need some clarification. If I want to
correctly remove an element from a red black tree that I have found and free
it's memory allocation, this code should work, right?
find.i = 400;
n = RB_FIND(inttree, &head, &find);
if (n != NULL) {
n = RB_REMOVE(inttree, &head, n);
free(n);
} else if (n == NULL)
(void)printf("satisfied NULL check\n");
I ask because the man page is clear for splay trees, but I am not certain for
Red Black trees. I looked at /usr/include/sys/tree.h, and I did not find any
explicit free's.
I assume that since RB_REMOVE will provide me with a pointer to the removed
element, that all I need to do is free it.
Also, is the above the most efficient way to find and remove an element from a
red black tree?
Cheers,
Brian
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]