Guardian Native C Library Calls Reference Manual (G06.28+, H06.04+)

Guardian Native C Library Calls (t - z) 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 native Guardian processes: $SYSTEM.ZDLLnnn.ZCRTLDLL
H-series OSS processes: /G/system/zdllnnn/zcrtldll
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 Species the name of a routine to be invoked at each node during a walk-through
the binary tree.
DESCRIPTION
The tsearch(), tnd(), tdelete(), and twalk() functions are used to operate on binary search
trees.
The twalk() function traverses a binary search tree. The root parameter species 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 rst parameter species the address of the visited node. The
second parameter species a value from an enum data type, which is dened in the search.h
header le 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 rst
(preorder), second (postorder), or third (endorder) time that the node has been visited during a
depth-rst, 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), tnd(3), tdelete(3), tsearch(3), qsort(3).
527192-005 Hewlett-Packard Company 731