This commit is contained in:
Macko 2024-04-10 23:29:11 +02:00
parent a790569a53
commit e48d2bf689

View File

@ -19,7 +19,7 @@ struct snake* add_snake(struct snake* snake, int x, int y) {
return snake;
}*/
struct snake* remove_snake(struct snake* snake) {
/*struct snake* remove_snake(struct snake* snake) {
if (snake == NULL) {
return NULL;
}
@ -30,9 +30,23 @@ struct snake* remove_snake(struct snake* snake) {
free(temp->next);
temp->next = NULL;
return snake;
}*/
struct snake* remove_snake(struct snake* snake) {
if (snake == NULL || snake->next == NULL) {
return NULL;
}
struct snake* temp = snake;
while(temp->next->next != NULL) {
temp = temp->next;
}
free(temp->next);
temp->next = NULL;
return snake;
}
int is_snake(struct snake* snake, int x, int y) {
while(snake != NULL) {
if(snake->x == x && snake->y == y) {