www.delorie.com/gnu/docs/avl/libavl_235.html   search  
 
Buy GNU books!


GNU libavl 2.0.1

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

14.5.3 Starting at a Found Node

To start from a particular item, we search for it in the tree. If it exists then we initialize the traverser to it. Otherwise, we initialize the traverser to the null item and return a null pointer. There are no surprises here.

 
void *
pbst_t_find (struct pbst_traverser *trav, struct pbst_table *tree, void *item)
{ struct pbst_node *p; int dir; assert (trav != NULL && tree != NULL && item != NULL); trav-&#62;pbst_table = tree; for (p = tree-&#62;pbst_root; p != NULL; p = p-&#62;pbst_link[dir])
{ int cmp = tree-&#62;pbst_compare (item, p-&#62;pbst_data, tree-&#62;pbst_param); if (cmp == 0)
{ trav-&#62;pbst_node = p; return p-&#62;pbst_data; } dir = cmp > 0; } trav-&#62;pbst_node = NULL; return NULL; }
This code is included in @refalso{502


  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003