Open System Services Library Calls Reference Manual (G06.29+, H06.08+, J06.03+)

OSS Library Calls (t - v) twalk(3)
NAME
twalk - Traverses a binary search tree
LIBRARY
G-series native Guardian processes: $SYSTEM.SYSnn.ZCRTLSRL
G-series native OSS processes: /G/system/sysnn/zcrtlsrl
H-series and J-series native Guardian processes: $SYSTEM.ZDLLnnn.ZCRTLDLL
32-bit H-series and J-series OSS processes: /G/system/zdllnnn/zcrtldll
64-bit H-series and J-series OSS processes: /G/system/zdllnnn/ycrtldll
SYNOPSIS
#include <search.h>
void twalk(
const void *root,
void (*action) (const void *, VISIT, int) );
PARAMETERS
root Points to the root of the binary tree to be walked.
action Specifies the name of a routine to be invoked at each node during a walk-through
the binary tree.
DESCRIPTION
The tsearch( ), tfind( ), tdelete( ), and twalk( ) functions are used to operate on binary search
trees.
The twalk( ) function traverses a binary search tree. The root parameter specifies the root of the
binary tree to be traversed. Any node in a binary tree can be used as the root node for a walk
below that node.
The action parameter is the name of a routine to be invoked at each node. This action routine is
called with three parameters. The first parameter specifies the address of the visited node. The
second parameter specifies a value from an enum data type, which is defined in the search.h
header file as follows:
typedef enum { preorder, postorder, endorder, leaf } VISIT
The value of the second parameter in the action routine depends on whether this is the first
(preorder), second (postorder), or third (endorder) time that the node has been visited during a
depth-first, left-to-right traversal of the tree, or whether the node is a leaf. (A leaf is a node that is
not the parent of another node). The third parameter in the action routine is the level of the node
in the binary tree with the root being level 0 (zero).
NOTES
The twalk( ) funciton is reentrant, but care should be taken to ensure that the function supplied as
the argument to action is also reentrant.
RETURN VALUES
The twalk( ) function returns no value.
RELATED INFORMATION
Functions: bsearch(3), hsearch(3), lsearch(3), tfind(3), tdelete(3), tsearch(3), qsort(3).
527187-017 Hewlett-Packard Company 773