Next: , Previous: Walk, Up: Private Routines


3.2.19 uWalk

Walk a tree, performing an action at specified traversals of each node.

Synopsis

     #include <rbtree/rbtree.h>
     
     
     
static int uWalk( Tree *tree, Node *node, int (*action)(void *data,Visit visit,unsigned long level,void *udata), void *udata, SiblingOrder sibling_order, Visit visit, unsigned long level );

Parameters

Tree *tree
the tree to walk
Node *node
the node at which to start. must be ROOT(tree)
int (*action)(void *data,Visit visit,unsigned long level,void *udata)
the action routine
void *udata
a pointer to data to be passed to the action routine
SiblingOrder sibling_order
the order in which to walk
          
          
Possible values for a SiblingOrder are as follows: LEFT_TO_RIGHT, RIGHT_TO_LEFT
Visit visit
the traversal(s) at which to call the action routine
          
          
Possible values for a Visit are as follows: PRE_ORDER, IN_ORDER, POST_ORDER
unsigned long level
the level of the passed node. ‘0’ if the root node.

Description

uWalk traverse a tree, calling a user supplied action routine at selectable traversals of each node (any combination of pre-order, in-order, or post-order). The action routine is informed of which node traversal and which tree level it is called from. the walk is aborted if the action routine returns non-zero. This routine differs from Walk in that it can pass along a pointer provided by the calling routine to the action routine, allowing arbitrary data to be available to the action routine.

The traversals at which the action routine is called at are specified by the logical or of PRE_ORDER, IN_ORDER, or POST_ORDER.

Returns

If the action routines all return ‘0’, it returns ‘0’, else it returns the value returned by the last action routine called.