Add solution for clear archive (bst).

This commit is contained in:
paulusja 2025-12-11 12:28:24 +01:00
parent 93aaf59201
commit 1c76a98186
2 changed files with 17 additions and 15 deletions

View File

@ -28,13 +28,13 @@ int main()
printf("\nNames in archive:\n");
printNames();
printf("\n");
*/
printf("Clearing archive ...\n");
clearArchive();
printf("\nNames in archive:\n");
printNames();
printf("\n");*/
printf("\n");
return EXIT_SUCCESS;
}

View File

@ -69,12 +69,6 @@ void printNames()
printNamesRec(root);
}
/*
static void disposeElem(QueueElem *elem)
{
if(elem != NULL)
free(elem->name);
free(elem);
}
static QueueElem *removeElemRek(QueueElem *elem, const char *name)
{
@ -96,19 +90,27 @@ void removeName(const char *name)
{
head = removeElemRek(head, name);
}
*/
static void clearElemRek(QueueElem *elem)
static void disposeNode(Node *node)
{
if(elem != NULL)
if(node != NULL)
free(node->name);
free(node);
}
static void clearNodeRec(Node *node)
{
if(node != NULL)
{
clearElemRek(elem->next);
disposeElem(elem);
clearNodeRec(node->left);
clearNodeRec(node->right);
disposeNode(node);
}
}
void clearArchive()
{
clearElemRek(head);
head = NULL;
clearNodeRec(root);
root = NULL;
}
*/