Изменил(а) на 'du7/snake.c'

This commit is contained in:
Vladyslav Korzun 2023-04-20 06:17:06 +00:00
parent bdb6a9b609
commit 3c3f421d33

View File

@ -10,15 +10,20 @@ 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) {
struct snake* this = head; if (snake == NULL || snake->next == NULL) {
this = this->next; free(snake);
while (this->next != NULL){ return NULL;
this = this->next;
} }
this = head; struct snake* current = snake;
while (this != NULL){ struct snake* prev = NULL;
// Niečo môžme s prvkom this spraviť while (current->next != NULL) {
this= this->next; prev = current;
current = current->next;
}
free(current);
current = NULL;
prev->next = NULL;
} }
} }