www.delorie.com/gnu/docs/avl/libavl_57.html   search  
 
Buy GNU books!


GNU libavl 2.0.1

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.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:

 
void *
bst_t_copy (struct bst_traverser *trav, const struct bst_traverser *src)
{ assert (trav != NULL && src != NULL); if (trav != src)
{ trav-&#62;bst_table = src-&#62;bst_table; trav-&#62;bst_node = src-&#62;bst_node; trav-&#62;bst_generation = src-&#62;bst_generation; if (trav-&#62;bst_generation == trav-&#62;bst_table-&#62;bst_generation)
{ trav-&#62;bst_height = src-&#62;bst_height; memcpy (trav-&#62;bst_stack, (const void *) src-&#62;bst_stack, sizeof *trav-&#62;bst_stack * trav-&#62;bst_height); } } return trav-&#62;bst_node != NULL ? trav-&#62;bst_node-&#62;bst_data : NULL; }
This code is included in @refalso{63

Exercises:

1. Without the check that trav != src before copying src into trav, what might happen? [answer]


  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003