domaca_uloha_7
This commit is contained in:
		
							parent
							
								
									4d74b16736
								
							
						
					
					
						commit
						bd05b81d3e
					
				
							
								
								
									
										20
									
								
								du7/snake.c
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								du7/snake.c
									
									
									
									
									
								
							@ -18,11 +18,23 @@ 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 == NULL) return NULL;
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	struct snake* nasledujuci = calloc(1, sizeof(struct snake));
 | 
						else if (snake->next == NULL) {
 | 
				
			||||||
	nasledujuci->next = snake->next;
 | 
							free(snake);
 | 
				
			||||||
	free(snake);
 | 
							return NULL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
    return nasledujuci;
 | 
						else {
 | 
				
			||||||
 | 
							struct snake* medzipamat = calloc(1, sizeof(struct snake));
 | 
				
			||||||
 | 
							medzipamat = snake
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							while (1) {
 | 
				
			||||||
 | 
								snake = snake->next;
 | 
				
			||||||
 | 
								if (snake->next->next == NULL) break;
 | 
				
			||||||
 | 
							} 
 | 
				
			||||||
 | 
							free(snake->next->next);
 | 
				
			||||||
 | 
							snake->next = NULL;
 | 
				
			||||||
 | 
							return medzipamat;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void free_snake(struct snake* sn){
 | 
					void free_snake(struct snake* sn){
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user