From 4adb5991169b2598970971e5613e667506c02f08 Mon Sep 17 00:00:00 2001 From: Weber Date: Tue, 16 Apr 2024 16:16:51 +0000 Subject: [PATCH] test --- cv9/snake.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/cv9/snake.c b/cv9/snake.c index f1f94e7..3c522f6 100644 --- a/cv9/snake.c +++ b/cv9/snake.c @@ -11,10 +11,25 @@ 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* hlava = snake->next; - free(snake); - return hlava; + if (!snake) return NULL; + + struct snake* current = snake; + struct snake* previous = NULL; + + while (current->next) { + previous = current; + current = current->next; + } + + if (previous) { + previous->next = NULL; + } else { + free(current); + return NULL; + } + + free(current); + return snake; } void free_snake(struct snake* sn){