test
This commit is contained in:
parent
12e3e04c85
commit
4adb599116
23
cv9/snake.c
23
cv9/snake.c
@ -11,10 +11,25 @@ struct snake* add_snake(struct snake* snake, int x, int y) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct snake* remove_snake(struct snake* snake) {
|
struct snake* remove_snake(struct snake* snake) {
|
||||||
if (snake == NULL) return NULL;
|
if (!snake) return NULL;
|
||||||
struct snake* hlava = snake->next;
|
|
||||||
free(snake);
|
struct snake* current = snake;
|
||||||
return hlava;
|
struct snake* previous = NULL;
|
||||||
|
|
||||||
|
while (current->next) {
|
||||||
|
previous = current;
|
||||||
|
current = current->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (previous) {
|
||||||
|
previous->next = NULL;
|
||||||
|
} else {
|
||||||
|
free(current);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(current);
|
||||||
|
return snake;
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_snake(struct snake* sn){
|
void free_snake(struct snake* sn){
|
||||||
|
Loading…
Reference in New Issue
Block a user