added function to destroy list

This commit is contained in:
Данила Горнушко 2023-11-29 12:01:20 +03:00
parent c86191a104
commit 28c7242587
3 changed files with 26 additions and 41 deletions

View file

@ -1,18 +1,5 @@
#ifndef LIST_DEF
#define LIST_DEF 1
/*
File: list.c
Description: Implementation of linked list object functionality.
Created: March 21, 2017
Author: Matt Mumau
*/
// System dependencies
#include <stdlib.h>
// Header
#include "list.h"
#include <stdlib.h>
void list_push(List** head, void* data) {
List* node = malloc(sizeof(List));
@ -108,4 +95,10 @@ void list_remove(List** head, unsigned int index) {
}
}
#endif
void list_destroy(List** head) {
while (*head != NULL) {
List* tmp_cursor = *head;
*head = (*head)->next;
free(tmp_cursor);
}
}

View file

@ -1,46 +1,30 @@
#ifndef LIST_H_DEF
#define LIST_H_DEF 1
/*
File: list.h
Description: Linked list library definition
Created: March 21, 2017
Author: Matt Mumau
*/
#define LIST_H_DEF
typedef struct List {
void* data;
struct List* next;
} List;
/*
Push data to the end of the list.
*/
// Push data to the end of the list.
void list_push(List** head, void* data);
/*
Remove the final element of the list and return its data.
*/
// Remove the final element of the list and return its data.
void* list_pop(List** head);
/*
Insert the data object to the beginning of the list.
*/
// Insert the data object to the beginning of the list.
void list_insert(List** head, void* data);
/*
Get the size of the list.
*/
// Get the size of the list.
unsigned int list_sizeof(List* head);
/*
Get the data of the node at the given ordinal number in the list.
*/
// Get the data of the node at the given ordinal number in the list.
List* list_get(List* head, unsigned int index);
/*
Delete the item in the list at the given ordinal location (1 is the first).
*/
// Delete the item in the list at the given ordinal location (1 is the first).
void list_remove(List** head, unsigned int index);
// Remove all element of the list and set the given ptr to NULL
void list_destroy(List** head);
#endif

View file

@ -4,6 +4,7 @@
#include "esp_log.h"
#include "hal/twai_types.h"
#include "inttypes.h"
#include "list.h"
#include "sdkconfig.h"
#include "freertos/projdefs.h"
#include "string.h"
@ -429,6 +430,13 @@ static int cansmartfilter(int argc, char **argv) {
arg_print_errors(stderr, cansmart_args.end, argv[0]);
return 1;
}
list_destroy(&adv_filters.filters);
for (int i = 0; i < cansmart_args.filters->count; i++) {
}
return 0;
}