Implement removePersonFromList function to delete a person node from the linked list; update documentation in users.h

This commit is contained in:
2025-05-13 10:41:18 +02:00
parent 0a5f176582
commit 6fcbe861ae
3 changed files with 43 additions and 6 deletions
+32
View File
@@ -159,4 +159,36 @@ int addTimeEvent(
_person->user.last_time_event = current_time;
return 1;
}
int removePersonFromList(node_t **_head, node_t **_person)
{
if (_head == NULL || *_head == NULL || _person == NULL || *_person == NULL)
return 0;
node_t *current = *_head;
node_t *prev = NULL;
while (current != NULL)
{
if (current == *_person)
{
if (prev == NULL)
{
*_head = current->next;
}
else
{
prev->next = current->next;
}
free(current->user.name);
free(current->user.surname);
free(current);
*_person = NULL;
return 1;
}
prev = current;
current = current->next;
}
return 0;
}