TWALK - traverse through binary tree.

(Compatible with UNIX System V C)

Usage:

#include <search.h>
void twalk();
twalk(root,action);

Where:

char *root;
points to the root of the tree that you want to walk. This can also be a node of a tree, in which case "twalk" traverses the subtree beneath that node.
void (*action)(char *,int,int);
points to a function that will be performed at every node in the tree as "twalk" walks by (see below).

Description:

"twalk" traverses all the nodes in a binary tree, invoking the "action" function at each node. "action" is called with three arguments. The first is the address of the node that "twalk" is currently looking at. The second is a value from the enumerated type

typedef enum {
    preorder, postorder, endorder, leaf
} VISIT;

(defined in <search.h>). "preorder" indicates that this is the first time the node has been visited (on the way down the tree). "postorder" indicates the second visit (on the way back from the "left" subtree). "endorder" indicates the third visit (on the way back from the "right" subtree). "leaf" indicates that the node is a leaf (and will therefore only be visited once).

The third argument of "action" is an integer giving the level of the current node in the tree. This is the number of nodes lying above the current node. The level of the root is zero, the level of the root's children is one, and so on.

Note that the level of indirection for the "root" argument is one less than the level for the related functions "tsearch", "tfind", and "tdelete".

See Also:

expl c lib tfind

expl c lib tdelete

expl c lib tsearch

Copyright © 1996, Thinkage Ltd.