Added function to delete contents of AVL tree

This commit is contained in:
2023-11-07 12:31:16 -06:00
parent 9fb5b69745
commit 185d3f6677
2 changed files with 18 additions and 1 deletions

View File

@@ -38,4 +38,12 @@ struct avltree_t *avl_remove(struct avltree_t *tree, int key);
* @param key * @param key
* @return void* * @return void*
*/ */
void *avl_get(struct avltree_t *tree, int key); void *avl_get(struct avltree_t *tree, int key);
/**
* @brief Removes every node present on the given tree.
*
* @param tree
* @return NULL
*/
void *avl_clear(struct avltree_t *tree);

View File

@@ -198,4 +198,13 @@ void *avl_get(struct avltree_t *tree, int key)
} }
} }
return NULL; return NULL;
}
void *avl_clear(struct avltree_t *tree)
{
while(tree != NULL)
{
tree = avl_remove(tree, tree->key);
}
return tree;
} }