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));
@ -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;
} }