fixed list free function.
This commit is contained in:
		
							parent
							
								
									69daec541c
								
							
						
					
					
						commit
						c1375f3882
					
				| 
						 | 
				
			
			@ -67,10 +67,11 @@ Free List node:
 | 
			
		|||
	de-allocates memory for a list, and all next items recursively.
 | 
			
		||||
*/
 | 
			
		||||
void TEMPLATE(free,LIST_NODE)(LIST_NODE* list){
 | 
			
		||||
	if (list->next != NULL){
 | 
			
		||||
		TEMPLATE(free,LIST_NODE)(list->next);
 | 
			
		||||
	while (list->next != NULL){
 | 
			
		||||
		LIST_NODE* next = list->next;
 | 
			
		||||
		free(list);
 | 
			
		||||
		list = next;
 | 
			
		||||
	}
 | 
			
		||||
	free(list);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										16
									
								
								test.c
								
								
								
								
							
							
						
						
									
										16
									
								
								test.c
								
								
								
								
							| 
						 | 
				
			
			@ -26,16 +26,12 @@ int main(int argc, char* argv[]){
 | 
			
		|||
	push_double_stack(42.5, &s);
 | 
			
		||||
	print_double_stack(s);
 | 
			
		||||
	
 | 
			
		||||
	float_list* l = new_float_list(5.0, NULL);
 | 
			
		||||
	l = add_float_list(6.0, l);
 | 
			
		||||
	l = add_float_list(7.0, l);
 | 
			
		||||
	l = add_float_list(8.0, l);
 | 
			
		||||
	printList(l);
 | 
			
		||||
	l = insert_float_list(15.5525, 2, l);
 | 
			
		||||
	l = insert_float_list(25, 0, l);
 | 
			
		||||
	printList(l);
 | 
			
		||||
	l = remove_float_list(2, l);
 | 
			
		||||
	printList(l);
 | 
			
		||||
	float_list* l = new_float_list(-1, NULL);
 | 
			
		||||
	printf("Start.\n");
 | 
			
		||||
	for (int i = 0; i < 100000000; i++){
 | 
			
		||||
		l = add_float_list(i*i, l);
 | 
			
		||||
	}
 | 
			
		||||
	printf("End.\n");
 | 
			
		||||
	free_float_list(l);
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue