From e48d2bf689f6f5d483676f434a3cc6bf2f4116fd Mon Sep 17 00:00:00 2001 From: Miloslav Macko Date: Wed, 10 Apr 2024 23:29:11 +0200 Subject: [PATCH] 1111 --- cv9/snake.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cv9/snake.c b/cv9/snake.c index ddfa9e2..dd1e357 100644 --- a/cv9/snake.c +++ b/cv9/snake.c @@ -19,7 +19,7 @@ struct snake* add_snake(struct snake* snake, int x, int y) { return snake; }*/ -struct snake* remove_snake(struct snake* snake) { +/*struct snake* remove_snake(struct snake* snake) { if (snake == NULL) { return NULL; } @@ -30,9 +30,23 @@ struct snake* remove_snake(struct snake* snake) { free(temp->next); temp->next = NULL; return snake; +}*/ + +struct snake* remove_snake(struct snake* snake) { + if (snake == NULL || snake->next == NULL) { + return NULL; + } + struct snake* temp = snake; + while(temp->next->next != NULL) { + temp = temp->next; + } + free(temp->next); + temp->next = NULL; + return snake; } + int is_snake(struct snake* snake, int x, int y) { while(snake != NULL) { if(snake->x == x && snake->y == y) {