opsoiewjoiwerewr

This commit is contained in:
Michal Utľák 2024-04-09 17:28:01 +02:00
parent abf3c910a6
commit df7d0ccd00

View File

@ -13,26 +13,22 @@ struct snake* add_snake(struct snake* snake,int x,int y){
}
struct snake* remove_snake(struct snake* snake){
if (snake == NULL) {
if (snake == NULL || snake->next == NULL) {
return NULL;
}
struct snake* nova_hlavicka = snake->next;
free(snake);
if (nova_hlavicka == NULL) {
return NULL;
struct snake* prev = NULL;
struct snake* current = snake;
while (current->next != NULL) {
prev = current;
current = current->next;
}
struct snake* chvost = nova_hlavicka;
while (chvost->next != NULL) {
chvost = chvost->next;
}
free(current);
prev->next = NULL;
chvost->next = NULL;
return nova_hlavicka;
return snake;
}
void free_snake(struct snake* sn){