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) {
if(snake == NULL || snake-> next == NULL) {
if (snake == NULL) {
return NULL;
}
if (snake->next == NULL) {
free(snake);
return NULL;
}
struct snake* previous = NULL;
struct snake* current = NULL;
while (current->next !=NULL) {
previous = current;
current = current->next;
struct snake* temp = snake;
while (temp->next->next != NULL) {
temp = temp->next;
}
if (previous !=NULL) {
free(current->next);
previous->next = NULL;
}
free(temp->next);
temp->next = NULL;
return snake;
}

Binary file not shown.