This commit is contained in:
Michal Utľák 2024-04-09 17:12:20 +02:00
parent 78f05087c6
commit abf3c910a6

View File

@ -1,6 +1,5 @@
#include "snake.h" #include "snake.h"
#include <stdlib.h> #include <stdlib.h>
#include <assert.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* hlavicka = calloc(1,sizeof(struct snake)); struct snake* hlavicka = calloc(1,sizeof(struct snake));
@ -14,7 +13,7 @@ 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){
if (snake == NULL) { if (snake == NULL) {
return NULL; return NULL;
} }
@ -25,11 +24,13 @@ struct snake* remove_snake(struct snake* snake){
if (nova_hlavicka == NULL) { if (nova_hlavicka == NULL) {
return NULL; return NULL;
} }
struct snake* chvost = nova_hlavicka; struct snake* chvost = nova_hlavicka;
while (chvost->next != NULL) { while (chvost->next != NULL) {
chvost = chvost->next; chvost = chvost->next;
} }
assert(chvost->next == NULL);
chvost->next = NULL;
return nova_hlavicka; return nova_hlavicka;
} }