From df7d0ccd003e0682f1589c78bb4522ab90247dee Mon Sep 17 00:00:00 2001 From: Michal Utlak Date: Tue, 9 Apr 2024 17:28:01 +0200 Subject: [PATCH] opsoiewjoiwerewr --- cv9/snake.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/cv9/snake.c b/cv9/snake.c index dc16a75..20d79f7 100644 --- a/cv9/snake.c +++ b/cv9/snake.c @@ -13,26 +13,22 @@ struct snake* add_snake(struct snake* snake,int x,int y){ } struct snake* remove_snake(struct snake* snake){ - if (snake == NULL) { - return NULL; - } - - struct snake* nova_hlavicka = snake->next; - - free(snake); - - if (nova_hlavicka == NULL) { + + if (snake == NULL || snake->next == NULL) { return NULL; } - struct snake* chvost = nova_hlavicka; - while (chvost->next != NULL) { - chvost = chvost->next; + struct snake* prev = NULL; + struct snake* current = snake; + while (current->next != NULL) { + prev = current; + current = current->next; } - chvost->next = NULL; - - return nova_hlavicka; + free(current); + prev->next = NULL; + + return snake; } void free_snake(struct snake* sn){