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) {