10.6.1 Starting at the First Node |
|
To find the first (least) item in the tree, we just descend all the way
to the left, as usual. In an RTBST, as in a BST, this involves checking
for null pointers.
396. <RTBST traverser first initializer 396> =
void *
rtbst_t_first (struct rtbst_traverser *trav, struct rtbst_table *tree)
{
assert (tree != NULL && trav != NULL);
trav->rtbst_table = tree;
trav->rtbst_node = tree->rtbst_root;
if (trav->rtbst_node != NULL)
{
while (trav->rtbst_node->rtbst_link[0] != NULL)
trav->rtbst_node = trav->rtbst_node->rtbst_link[0];
return trav->rtbst_node->rtbst_data;
}
else
return NULL;
}
This code is included in 395.
10.6 Traversal
|
10.6 Traversal
|
10.6.2 Starting at the Last Node
|