refresh
This commit is contained in:
parent
a367fb958b
commit
9391f1ab50
20
du5/snake.c
20
du5/snake.c
@ -22,22 +22,22 @@ struct snake* add_snake (struct snake* snake, int x, int y) {
|
||||
}
|
||||
|
||||
struct snake* remove_snake(struct snake* snake) {
|
||||
if(snake == NULL || snake-> next == NULL) {
|
||||
if (snake == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (snake->next == NULL) {
|
||||
free(snake);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct snake* previous = NULL;
|
||||
struct snake* current = NULL;
|
||||
while (current->next !=NULL) {
|
||||
previous = current;
|
||||
current = current->next;
|
||||
struct snake* temp = snake;
|
||||
while (temp->next->next != NULL) {
|
||||
temp = temp->next;
|
||||
}
|
||||
|
||||
if (previous !=NULL) {
|
||||
free(current->next);
|
||||
previous->next = NULL;
|
||||
}
|
||||
free(temp->next);
|
||||
temp->next = NULL;
|
||||
|
||||
return snake;
|
||||
}
|
||||
|
BIN
du5/snake.o
BIN
du5/snake.o
Binary file not shown.
Loading…
Reference in New Issue
Block a user