Изменил(а) на '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* this = head;
this = this->next;
while (this->next != NULL){
this = this->next;
}
this = head;
while (this != NULL){
// Niečo môžme s prvkom this spraviť
this= this->next;
if (snake == NULL || snake->next == NULL) {
free(snake);
return NULL;
}
struct snake* current = snake;
struct snake* prev = NULL;
while (current->next != NULL) {
prev = current;
current = current->next;
}
free(current);
current = NULL;
prev->next = NULL;
}
}