struct snake* remove_snake(struct snake* snake) { if (snake == NULL) { return NULL; } struct snake* current = snake; struct snake* prev = NULL; while (current->next != NULL) { prev = current; current = current->next; } if (prev != NULL) { prev->next = NULL; } else { // If prev is NULL, it means we are removing the head of the list // and the new head will be the next node snake = NULL; } free(current); return snake; }