[ADD] Extended list functionality (added node search)

This commit is contained in:
max 2024-10-28 19:40:00 +01:00
parent 4c9c547e62
commit c3a2f00edc
2 changed files with 19 additions and 1 deletions

View File

@ -4,7 +4,7 @@
#include "list.h" #include "list.h"
list_node * insert_end(list_node* list, void* data) list_node * insert_node(list_node* list, void* data)
{ {
list_node* node = (list_node*)malloc(sizeof(list_node)); list_node* node = (list_node*)malloc(sizeof(list_node));
if (node == NULL) if (node == NULL)
@ -60,4 +60,21 @@ void iterate_list(list_node* list, bool forward, int (*iterFunc)(const void*))
else else
current = current->previous; current = current->previous;
} }
}
list_node* find_node(list_node* list_start, bool forward, int (*findFunc)(const void*))
{
if (list_start == NULL || findFunc == NULL)
return NULL;
list_node* current = list_start;
while (current != NULL)
{
if (findFunc(current->data) == 1)
return current;
if (forward)
current = current->next;
else
current = current->previous;
}
return NULL;
} }

View File

@ -20,6 +20,7 @@ int shutdown_logger(const void* data)
free(logger); free(logger);
return 0; return 0;
} }
void shutdown_log(app_logger_info* appLogger) void shutdown_log(app_logger_info* appLogger)
{ {
canLog = false; canLog = false;