From bdb6a9b60929e918d37af2b262618dfd3b6299cf Mon Sep 17 00:00:00 2001 From: Vladyslav Korzun Date: Thu, 20 Apr 2023 06:16:10 +0000 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB(?= =?UTF-8?q?=D0=B0)=20=D0=BD=D0=B0=20'du7/snake.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du7/snake.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/du7/snake.c b/du7/snake.c index e8d5350..da890dc 100644 --- a/du7/snake.c +++ b/du7/snake.c @@ -10,20 +10,18 @@ struct snake* add_snake(struct snake* snake, int x, int y) { } struct snake* remove_snake(struct snake* snake) { - struct snake* prev = NULL; - struct snake* curr = snake; - while (curr->next != NULL) { - prev = curr; - curr = curr->next; - } - free(curr); - if (prev != NULL) { - prev->next = NULL; - return snake; - } else { - return NULL; - } +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; +} +} + void free_snake(struct snake* sn) { while (sn != NULL) {