2024-04-08 13:14:43 +00:00
|
|
|
struct snake* remove_snake(struct snake* snake) {
|
|
|
|
if (snake == NULL) {
|
2024-04-08 13:16:50 +00:00
|
|
|
return NULL;
|
2024-04-08 13:14:43 +00:00
|
|
|
}
|
2024-04-08 13:23:28 +00:00
|
|
|
struct snake* current = snake;
|
|
|
|
struct snake* prev = NULL;
|
|
|
|
while (current->next != NULL) {
|
|
|
|
prev = current;
|
|
|
|
current = current->next;
|
2024-04-08 13:14:43 +00:00
|
|
|
}
|
2024-04-08 13:23:28 +00:00
|
|
|
if (prev != NULL) {
|
|
|
|
prev->next = NULL;
|
|
|
|
} else {
|
|
|
|
// If prev is NULL, it means we are removing the head of the list
|
|
|
|
// and the new head will be the next node
|
|
|
|
snake = NULL;
|
2024-04-08 13:14:43 +00:00
|
|
|
}
|
2024-04-08 13:23:28 +00:00
|
|
|
free(current);
|
|
|
|
return snake;
|
2024-04-08 13:16:50 +00:00
|
|
|
}
|
|
|
|
|