From 8b6ffcb16b064a412971374dd56bf6e5bf4f1edf Mon Sep 17 00:00:00 2001 From: Michal Utlak Date: Tue, 9 Apr 2024 17:02:39 +0200 Subject: [PATCH] skuska --- cv9/snake.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cv9/snake.c b/cv9/snake.c index a2ae686..5d2df07 100644 --- a/cv9/snake.c +++ b/cv9/snake.c @@ -18,11 +18,23 @@ struct snake* remove_snake(struct snake* snake){ return NULL; } - struct snake* nova_hlavicka = snake->next; + struct snake* nova_hlavicka = snake->next; free(snake); - assert(nova_hlavicka == NULL || nova_hlavicka->next == NULL); + + if (nova_hlavicka == NULL || nova_hlavicka->next == NULL) { + assert(nova_hlavicka == NULL || nova_hlavicka->next == NULL); + return nova_hlavicka; + } + + + struct snake* chvost = nova_hlavicka; + while (chvost->next != NULL) { + chvost = chvost->next; + } + + assert(chvost->next == NULL); return nova_hlavicka; }