|
@@ -33,7 +33,7 @@ void avl_rotation_rr(avl_node * critical);
|
|
|
void printAVL(avl_node * r);
|
|
|
|
|
|
|
|
|
-/* define function declsred in avl.h */
|
|
|
+/* define function declared in avl.h */
|
|
|
|
|
|
avl_tree avl_make(const generic_cell k, const long n)
|
|
|
{
|
|
@@ -57,6 +57,32 @@ avl_tree avl_make(const generic_cell k, const long n)
|
|
|
return root;
|
|
|
}
|
|
|
|
|
|
+void avl_destroy(avl_tree root)
|
|
|
+{
|
|
|
+ struct avl_node *it;
|
|
|
+ struct avl_node *save = root;
|
|
|
+
|
|
|
+ /*
|
|
|
+ Rotate away the left links so that
|
|
|
+ we can treat this like the destruction
|
|
|
+ of a linked list
|
|
|
+ */
|
|
|
+ while((it = save) != NULL) {
|
|
|
+ if (it->left_child == NULL) {
|
|
|
+ /* No left links, just kill the node and move on */
|
|
|
+ save = it->right_child;
|
|
|
+ G_free(it);
|
|
|
+ it = NULL;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ /* Rotate away the left link and check again */
|
|
|
+ save = it->left_child;
|
|
|
+ it->left_child = save->right_child;
|
|
|
+ save->right_child = it;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
long howManyCell(const avl_tree root, const generic_cell k)
|
|
|
{
|