4.9.3.6 Initialization by Copying |
This function copies one traverser to another. It only copies the stack of parent pointers if they are up-to-date:
69. <BST traverser copy initializer 69> = void *
bst_t_copy (struct bst_traverser *trav, const struct bst_traverser *src)
{ assert (trav != NULL && src != NULL); if (trav != src)
{ trav->bst_table = src->bst_table; trav->bst_node = src->bst_node; trav->bst_generation = src->bst_generation; if (trav->bst_generation == trav->bst_table->bst_generation)
{ trav->bst_height = src->bst_height; memcpy (trav->bst_stack, (const void *) src->bst_stack, sizeof *trav->bst_stack * trav->bst_height); } } return trav->bst_node != NULL ? trav->bst_node->bst_data : NULL; }
Exercises:
1. Without the check that trav != src before copying src into trav, what might happen? [answer]
4.9.3.5 Starting at an Inserted Node | 4.9.3 Better Iterative Traversal | 4.9.3.7 Advancing to the Next Node |