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


GNU libavl 2.0.1

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

14.5.6 Backing Up to the Previous Node

This is the same as advancing a traverser, except that we reverse the directions.

 
void *
pbst_t_prev (struct pbst_traverser *trav)
{ assert (trav != NULL); if (trav-&#62;pbst_node == NULL) return pbst_t_last (trav, trav-&#62;pbst_table); else if (trav-&#62;pbst_node-&#62;pbst_link[0] == NULL)
{ struct pbst_node *q, *p; /* Current node and its child. */ for (p = trav-&#62;pbst_node, q = p-&#62;pbst_parent; ;
p = q, q = q-&#62;pbst_parent) if (q == NULL || p == q-&#62;pbst_link[1])
{ trav-&#62;pbst_node = q; return trav-&#62;pbst_node != NULL ? trav-&#62;pbst_node-&#62;pbst_data : NULL; } }
else
{ trav-&#62;pbst_node = trav-&#62;pbst_node-&#62;pbst_link[0]; while (trav-&#62;pbst_node-&#62;pbst_link[1] != NULL) trav-&#62;pbst_node = trav-&#62;pbst_node-&#62;pbst_link[1]; return trav-&#62;pbst_node-&#62;pbst_data; } }
This code is included in @refalso{502

See also: [ Cormen 1990], section 13.2.


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