1
1
mirror of https://github.com/theoludwig/libcproject.git synced 2025-05-21 23:21:15 +02:00

feat: add queue_free

This commit is contained in:
2023-08-03 22:57:32 +02:00
parent 6a40df3ad1
commit 1e475a59b1
4 changed files with 23 additions and 1 deletions

View File

@ -63,7 +63,7 @@ struct linked_list *linked_list_reverse(struct linked_list *list);
void linked_list_reverse_mutate(struct linked_list *list);
/**
* @brief Free the linked list.
* @brief Frees the linked list.
* @since v2.1.0
*/
void linked_list_free(struct linked_list *list);

View File

@ -43,3 +43,16 @@ void *queue_pop(struct queue *queue) {
queue->length = queue->length - 1;
return data;
}
void queue_free(struct queue *queue) {
if (queue == NULL) {
exit(EXIT_FAILURE);
}
struct queue_node *node = queue->first;
while (node != NULL) {
struct queue_node *node_next = node->next;
free(node);
node = node_next;
}
free(queue);
}

View File

@ -42,4 +42,10 @@ void queue_push(struct queue *queue, void *data);
*/
void *queue_pop(struct queue *queue);
/**
* @brief Frees the queue.
* @since v2.1.0
*/
void queue_free(struct queue *queue);
#endif