1111
This commit is contained in:
parent
a790569a53
commit
e48d2bf689
16
cv9/snake.c
16
cv9/snake.c
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user