|
@@ -49,6 +49,31 @@ avlID_tree avlID_make(const long k, const long n)
|
|
|
return root;
|
|
|
}
|
|
|
|
|
|
+void avlID_destroy(avlID_tree root)
|
|
|
+{
|
|
|
+ struct avlID_node *it;
|
|
|
+ struct avlID_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 howManyID(const avlID_tree root, const long k)
|
|
|
{
|