This commit is contained in:
Oleksandr Vyshniakov 2025-04-09 22:37:35 +02:00
parent a367fb958b
commit 9391f1ab50
2 changed files with 10 additions and 10 deletions

View File

@ -22,22 +22,22 @@ struct snake* add_snake (struct snake* snake, int x, int y) {
} }
struct snake* remove_snake(struct snake* snake) { struct snake* remove_snake(struct snake* snake) {
if(snake == NULL || snake-> next == NULL) { if (snake == NULL) {
return NULL;
}
if (snake->next == NULL) {
free(snake); free(snake);
return NULL; return NULL;
} }
struct snake* previous = NULL; struct snake* temp = snake;
struct snake* current = NULL; while (temp->next->next != NULL) {
while (current->next !=NULL) { temp = temp->next;
previous = current;
current = current->next;
} }
if (previous !=NULL) { free(temp->next);
free(current->next); temp->next = NULL;
previous->next = NULL;
}
return snake; return snake;
} }

Binary file not shown.