HP-UX Reference (11i v1 05/09) - 3 Library Functions N-Z (vol 7)

t
tsearch(3C) tsearch(3C)
/* This routine prints out a node, the first time
twalk encounters it. */
void
print_node(element, order, level)
void *element;
VISIT order;
int level;
{
if (order == preorder || order == leaf)
{
(void) printf("string = %20s, length = %d\n",
(*(struct element **) element)->string,
(*(struct element **) element)->length);
}
}
RETURN VALUE
A NULL pointer is returned by tsearch() if there is not enough space available to create a new node.
A NULL pointer is returned by tsearch(), tfind(), and tdelete() if rootp is NULL
on entry.
If the datum is found, both
tsearch() and tfind() return a pointer to it. If not, tfind()
returns
NULL, and tsearch() returns a pointer to the inserted item.
WARNINGS
The root argument to twalk() is one level of indirection less than the rootp arguments to tsearch()
and tdelete().
Two nomenclatures are used to refer to the order in which tree nodes are visited.
tsearch() uses
preorder, postorder and endorder to respectively refer to visiting a node before any of its children, after its
left child and before its right and after both its children. The alternate nomenclature uses preorder,
inorder, and postorder to refer to the same visits, which could result in some confusion over the meaning of
postorder. If the calling function alters the pointer to the root, results are unpredictable.
SEE ALSO
bsearch(3C), hsearch(3C), lsearch(3C), thread_safety(5).
STANDARDS CONFORMANCE
tsearch(): AES, SVID2, SVID3, XPG2, XPG3, XPG4
tdelete(): AES, SVID2, SVID3, XPG2, XPG3, XPG4
tfind(): AES, SVID2, SVID3, XPG2, XPG3, XPG4
twalk(): AES, SVID2, SVID3, XPG2, XPG3, XPG4
HP-UX 11i Version 1: September 2005 3 Hewlett-Packard Company Section 31019