diff --git a/du4/snake.c b/du4/snake.c index b4d927b..b67688f 100644 --- a/du4/snake.c +++ b/du4/snake.c @@ -15,7 +15,21 @@ struct snake* add_snake(struct snake* snake,int x,int y){ } struct snake* remove_snake(struct snake* snake){ - return NULL; + + struct snake* clanok = snake; + + if (snake -> next == NULL) { + free(snake); + return NULL; + } + + while (clanok -> next -> next != NULL) { // posuvam sa po hadovi kym nenajdem koniec chvosta ktory odmazem + clanok = clanok -> next; + } + + free (clanok -> next); //po tom co som nasiel kde je koniec, odmazem koniec chvosta a korunujem nasledujuci clanok novym koncom + clanok -> next = NULL; + return snake; //kedze som menil snaka podla referenciam v pamati, mozem vratit noveho stareho hada } void free_snake(struct snake* sn){