mirror of
				https://gitlab.com/klmp200/LO41.git
				synced 2025-10-31 09:13:06 +00:00 
			
		
		
		
	Fonction contains, j'ai pas testé lol
This commit is contained in:
		
							
								
								
									
										23
									
								
								List/List.c
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								List/List.c
									
									
									
									
									
								
							| @@ -140,6 +140,26 @@ void insert_inside_List(THIS(List), void * data, size_t data_size, int index){ | ||||
|  | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Check if data_to_find exist in list | ||||
|  * @param this THIS(List) | ||||
|  * @param data_to_find pointer to data you want to find inside | ||||
|  * @param compare a compare function, return true or false and takes two void * pointers | ||||
|  * @return true or false if the element is within the list or not | ||||
|  */ | ||||
| int contains_List(THIS(List), void * data_to_find, int (*compare)(void *, void *)){ | ||||
| 	Element * current = this->head; | ||||
|  | ||||
| 	while (current != NULL){ | ||||
| 		if (compare(data_to_find, current->data)){ | ||||
| 			return 1; | ||||
| 		} | ||||
| 		current = current->next; | ||||
| 	} | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| void remove_head_List(THIS(List)){ | ||||
| 	DELETE(this->head); | ||||
| } | ||||
| @@ -170,7 +190,8 @@ List *_init_List(){ | ||||
| 			 clear_custom, | ||||
| 			 clear, | ||||
| 			 remove_head, | ||||
| 			 remove_tail | ||||
| 			 remove_tail, | ||||
| 			 contains | ||||
| 	) | ||||
| 	return l; | ||||
| } | ||||
|   | ||||
| @@ -29,6 +29,7 @@ struct o_List { | ||||
| 	PUBLIC void* (*get_element_data)(_THIS(List), int index); | ||||
|  | ||||
| 	PUBLIC int (*get_size)(_THIS(List)); | ||||
| 	PUBLIC int (*contains)(_THIS(List), void * data_to_find, int (*compare)(void *, void *)); | ||||
|  | ||||
| 	PUBLIC void (*set_custom_free)(_THIS(List), void (*custom_free)(void *)); | ||||
| 	PUBLIC void (*insert_inside)(_THIS(List), void * data, size_t data_size, int index); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user