Hi everyone. I'm tying to understand the instruction below. I wish someone could explain me what it means:
tree->destroy(((AvlNode*)(*position)->data)->data);
// destroy the left branch of the binary search tree starting from the specified node
static void destroy_left(BisTree* tree, BiTreeNode* node)
{
BiTreeNode **position;
// can't remove from an empty tree
if(bitree_size(tree) == 0)
return 1;
// determine where to destroy nodes
if(node == NULL)
position = &tree->root;
else
position = &node->left;
// destroy the nodes
if(*position != NULL)
{
destroy_left(tree, *position);
destroy_right(tree, *position);
if(tree->destroy != NULL)
{
// release the data of the AVL node
tree->destroy(((AvlNode*)(*position)->data)->data);
}
}
}
/*****************************************************************************
* *
* ------------------------------- bistree.h ------------------------------ *
* *
*****************************************************************************/
#ifndef BISTREE_H
#define BISTREE_H
#include "bitree.h"
/*****************************************************************************
* *
* Define balance factors for AVL trees. *
* *
*****************************************************************************/
#define AVL_LFT_HEAVY 1
#define AVL_BALANCED 0
#define AVL_RGT_HEAVY -1
/*****************************************************************************
* *
* Define a structure for nodes in AVL trees. *
* *
*****************************************************************************/
typedef struct AvlNode_ {
void *data;
int hidden;
int factor;
} AvlNode;
/*****************************************************************************
* *
* Implement binary search trees as binary trees. *
* *
*****************************************************************************/
typedef BiTree BisTree;
/*****************************************************************************
* *
* --------------------------- Public Interface --------------------------- *
* *
*****************************************************************************/
void bistree_init(BisTree *tree, int (*compare)(const void *key1, const void
*key2), void (*destroy)(void *data));
void bistree_destroy(BisTree *tree);
int bistree_insert(BisTree *tree, const void *data);
int bistree_remove(BisTree *tree, const void *data);
int bistree_lookup(BisTree *tree, void **data);
#define bistree_size(tree) ((tree)->size)
#endif