1: 
    2: 
    3:     4:     5:     6:     7:     8:     9:    10:    11:    12: 
   13: 
   14: #include <search.h>
   15: 
   16: typedef struct node_t
   17: {
   18:     char          *key;
   19:     struct node_t *llink, *rlink;
   20: } node;
   21: 
   22: 
   23: void *
   24: tfind(const void *vkey, void * const *vrootp,
   25:     int (*compar)(const void *, const void *))
   26: {
   27:     char *key = (char *)vkey;
   28:     node **rootp = (node **)vrootp;
   29: 
   30:     if (rootp == (struct node_t **)0)
   31:         return ((struct node_t *)0);
   32:     while (*rootp != (struct node_t *)0) {      
   33:         int r;
   34:         if ((r = (*compar)(key, (*rootp)->key)) == 0)  
   35:             return (*rootp);           
   36:         rootp = (r < 0) ?
   37:             &(*rootp)->llink :         
   38:             &(*rootp)->rlink;          
   39:     }
   40:     return (node *)0;
   41: }