Created
May 16, 2013 14:59
-
-
Save pilky/5592335 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//We use a typedef to make things simpler | |
typedef void (*rxt_enumerator)(char *key, char *value); | |
void rxt_enumerate_node(rxt_node *root, rxt_enumerator callback) { | |
if (!root) return; | |
if (root->color) { | |
if (root->color == 2) root = root->value; | |
//All we change is that instead of printing out, we now call the function supplied to us | |
if (callback) callback(root->key, root->value); | |
return; | |
} | |
rxt_enumerate_node(root->left, callback); | |
rxt_enumerate_node(root->right, callback); | |
} | |
//To print as before we create the following function | |
void printKeyValuePair(char *key, char *value) { | |
printf("%s: %s\n", root->key, (char*)root->value); | |
} | |
//Then you call rxt_enumerate_node() and pass in the supplied function | |
void someFunction() { | |
rxt_enumerate_node(myNode, printKeyValuePair); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment