mirror of
https://github.com/theoludwig/libcproject.git
synced 2024-11-08 22:31:31 +01:00
feat: add queue_free
This commit is contained in:
parent
6a40df3ad1
commit
1e475a59b1
@ -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);
|
||||
|
13
lib/queue.c
13
lib/queue.c
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -10,6 +10,7 @@ void queue_initialization_test() {
|
||||
struct queue *queue = queue_initialization();
|
||||
assert(queue->length == 0);
|
||||
assert(queue->first == NULL);
|
||||
queue_free(queue);
|
||||
}
|
||||
|
||||
void queue_push_test() {
|
||||
@ -22,6 +23,7 @@ void queue_push_test() {
|
||||
assert(((uintptr_t)queue->first->next->data) == 8);
|
||||
assert(((uintptr_t)queue->first->next->next->data) == 15);
|
||||
assert(queue->first->next->next->next == NULL);
|
||||
queue_free(queue);
|
||||
}
|
||||
|
||||
void queue_pop_test() {
|
||||
@ -35,4 +37,5 @@ void queue_pop_test() {
|
||||
assert(((uintptr_t)queue->first->data) == 8);
|
||||
assert(((uintptr_t)queue->first->next->data) == 15);
|
||||
assert(queue->first->next->next == NULL);
|
||||
queue_free(queue);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user