domaca_uloha_7

This commit is contained in:
Tomáš Vasiľ 2022-04-26 20:15:29 +02:00
parent 886f158cec
commit ce45e519a5

View File

@ -2,21 +2,24 @@
#include <stdlib.h> #include <stdlib.h>
struct snake* add_snake(struct snake* snake,int x,int y){ struct snake* add_snake(struct snake* snake,int x,int y){
struct snake* novyZaciatok = calloc(1, sizeof(struct snake)); struct snake* novyZaciatok = calloc(1, sizeof(struct snake)); //alokujem pamäť smerníka
novyZaciatok->x = x; novyZaciatok->x = x; //nastavím súradnice hada
novyZaciatok->y = y; novyZaciatok->y = y;
if (snake != NULL) { if (snake != NULL) { //ak má had telo,
novyZaciatok->next = snake; novyZaciatok->next = snake; //tak mu iba pridám hlavu
} else { } else {
novyZaciatok->next = NULL; novyZaciatok->next = NULL; //inak musím vytvoriť nové telo
} }
return novyZaciatok; return novyZaciatok;
} }
struct snake* remove_snake(struct snake* snake){ struct snake* remove_snake(struct snake* snake){
return NULL; struct snake* nasledujuci = snake->next;
free(snake);
return nasledujuci;
} }
void free_snake(struct snake* sn){ void free_snake(struct snake* sn){