list.c
/* Insert to a sorted list keeping the list sorted */
Insert to a sorted list keeping the list sorted
Insert to a sorted list keeping the list sorted
void list_insert_sorted(list_t *_list, void *element, comp_func comp_fn) 
{
	list_node_t *cur = _list->head;
	if (cur == NULL || comp_fn(list_node_get_data(cur),element) >= 0 ) {
		list_push(_list,element);
	} else {
		while(cur!=NULL && comp_fn(list_node_get_data(cur),element)<0) {
			cur = list_node_get_next(cur);
		}
		if (cur != NULL)list_insert_after(_list,list_node_get_prev(cur),element);
		else list_enqueue(_list,element);
	}
}
void list_insert_sorted ( list_t * _list , void * element , comp_func comp_fn ) { list_node_t * cur = _list -> head ; if ( cur == NULL || comp_fn ( list_node_get_data ( cur ) , element ) >= 0 ) { list_push ( _list , element ) ; } else { while ( cur != NULL && comp_fn ( list_node_get_data ( cur ) , element ) < 0 ) { cur = list_node_get_next ( cur ) ; } if ( cur != NULL ) list_insert_after ( _list , list_node_get_prev ( cur ) , element ) ; else list_enqueue ( _list , element ) ; } }
Insert to a sorted list keeping the list sorted
Insert to a sorted list keeping the list sorted
// Find correct position to insert