summaryrefslogtreecommitdiff
path: root/src/03/rb_tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/03/rb_tree.c')
-rw-r--r--src/03/rb_tree.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/03/rb_tree.c b/src/03/rb_tree.c
index b6d0700..27430f7 100644
--- a/src/03/rb_tree.c
+++ b/src/03/rb_tree.c
@@ -268,3 +268,11 @@ int rb_tree_height(RBTree *tree) {
return 1 + max(rb_tree_height(tree->left), rb_tree_height(tree->right));
}
+
+RBTree *rb_tree_find(RBTree *t, int value) {
+ if (!t)
+ return NULL;
+
+ int x = compare(value, t->value);
+ return x == 0 ? t : rb_tree_find(x < 0 ? t->left : t->right, value);
+}