odmazat chvost

This commit is contained in:
Kamil Gejdoš 2026-04-14 15:21:47 +00:00
parent 82bb5222c8
commit 41ea365d44

View File

@ -15,9 +15,23 @@ struct snake* add_snake(struct snake* snake,int x,int y){
} }
struct snake* remove_snake(struct snake* snake){ struct snake* remove_snake(struct snake* snake){
struct snake* clanok = snake;
if (snake -> next == NULL) {
free(snake);
return NULL; 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){ void free_snake(struct snake* sn){
} }