This commit is contained in:
Weber 2024-04-16 16:16:51 +00:00
parent 12e3e04c85
commit 4adb599116

View File

@ -11,10 +11,25 @@ struct snake* add_snake(struct snake* snake, int x, int y) {
}
struct snake* remove_snake(struct snake* snake) {
if (snake == NULL) return NULL;
struct snake* hlava = snake->next;
free(snake);
return hlava;
if (!snake) return NULL;
struct snake* current = snake;
struct snake* previous = NULL;
while (current->next) {
previous = current;
current = current->next;
}
if (previous) {
previous->next = NULL;
} else {
free(current);
return NULL;
}
free(current);
return snake;
}
void free_snake(struct snake* sn){