From ce45e519a509a41d29ca6601b2d162079a66d81a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Vasi=C4=BE?= Date: Tue, 26 Apr 2022 20:15:29 +0200 Subject: [PATCH] domaca_uloha_7 --- du7/snake.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/du7/snake.c b/du7/snake.c index de14c16..7c9c139 100644 --- a/du7/snake.c +++ b/du7/snake.c @@ -2,21 +2,24 @@ #include struct snake* add_snake(struct snake* snake,int x,int y){ - struct snake* novyZaciatok = calloc(1, sizeof(struct snake)); - novyZaciatok->x = x; + struct snake* novyZaciatok = calloc(1, sizeof(struct snake)); //alokujem pamäť smerníka + novyZaciatok->x = x; //nastavím súradnice hada novyZaciatok->y = y; - if (snake != NULL) { - novyZaciatok->next = snake; + if (snake != NULL) { //ak má had telo, + novyZaciatok->next = snake; //tak mu iba pridám hlavu } else { - novyZaciatok->next = NULL; + novyZaciatok->next = NULL; //inak musím vytvoriť nové telo } return novyZaciatok; } struct snake* remove_snake(struct snake* snake){ - return NULL; + struct snake* nasledujuci = snake->next; + free(snake); + + return nasledujuci; } void free_snake(struct snake* sn){