void find(char *s, char c) { int n = strlen(s); int ge = fine_ge(n, s, c); int le = find_le(n, s, c); printf("%s\n", s); printf(" %d %c <= %c\n", le, c, s[le]); printf(" %d %c >= %c\n", ge, c, s[ge]); }
/* find greatest point in subtree p that is <= k */ static rb_node *find_le(rb_node *p, rb_key k, rb_tree *t) { rb_compare compare = t->compare; while (p != NIL) { if (compare(p->k, k) <= 0) { /* p->k <= k */ rb_node *r = find_le(p->r, k, t); if (r) return r; else return p; } else /* p->k > k */ p = p->l; } return NULL; /* k < everything in subtree */ }
/* find greatest point in t <= k */ rb_node *rb_tree_find_le(rb_tree *t, rb_key k) { return find_le(t->root, k, t); }