Initialization
This commit is contained in:
parent
a4f6ef7cd2
commit
f458f07805
20
cv9/snake.c
20
cv9/snake.c
@ -10,11 +10,23 @@ struct snake* add_snake(struct snake* snake,int x,int y){
|
||||
}
|
||||
|
||||
struct snake* remove_snake(struct snake* snake) {
|
||||
struct snake* temp = snake;
|
||||
if (snake!= NULL) {
|
||||
snake = snake->next;
|
||||
free(temp);
|
||||
if (snake == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (snake->next == NULL) {
|
||||
free(snake);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct snake* current = snake;
|
||||
while (current->next->next != NULL) {
|
||||
current = current->next;
|
||||
}
|
||||
|
||||
free(current->next);
|
||||
current->next = NULL;
|
||||
|
||||
return snake;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user