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


GNU libavl 2.0.1

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

5.5 Creation

We need to write bst_create() to create an empty BST. All it takes is a little bit of memory allocation and initialization:

 
struct bst_table *
bst_create (bst_comparison_func *compare, void *param, struct libavl_allocator *allocator)
{ struct bst_table *tree; assert (compare != NULL); if (allocator == NULL) allocator = &bst_allocator_default; tree = allocator-&#62;libavl_malloc (allocator, sizeof *tree); if (tree == NULL) return NULL; tree-&#62;bst_root = NULL; tree-&#62;bst_compare = compare; tree-&#62;bst_param = param; tree-&#62;bst_alloc = allocator; tree-&#62;bst_count = 0; tree-&#62;bst_generation = 0; return tree; }
This code is included in @refalso{29


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