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; return snake;
}*/ }*/
struct snake* remove_snake(struct snake* snake) { /*struct snake* remove_snake(struct snake* snake) {
if (snake == NULL) { if (snake == NULL) {
return NULL; return NULL;
} }
@ -30,7 +30,21 @@ struct snake* remove_snake(struct snake* snake) {
free(temp->next); free(temp->next);
temp->next = NULL; temp->next = NULL;
return snake; 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) { int is_snake(struct snake* snake, int x, int y) {