Ejemplo n.º 1
0
END_TEST


START_TEST (test_List_prepend_2)
{
  List_prepend(L, "foo");
  List_prepend(L, "bar");

  fail_unless(List_size(L) == 2);

  /*
  fail_unless( !strcmp(L->head->item      , "bar") );
  fail_unless( !strcmp(L->head->next->item, "foo") );

  fail_unless(L->head->next == L->tail);
  fail_unless(L->tail->next == NULL   );
  */
}
Ejemplo n.º 2
0
int List_iteratorInsert(LinkedList* list, void* data) {
	if(list == NULL || data == NULL) {
		return(LIST_ERR_NULL_ARG);
	}
	if(list->_curNode == list->_firstNode) {
		return(List_prepend(list, data));
	}
	_insertNode(list->_curNode->prev, list->_curNode, data);
	return(LIST_FUNC_SUCCESS);
}
Ejemplo n.º 3
0
END_TEST

START_TEST (test_List_accessWithNULL)
{

  // test null arguments
  List_add (NULL, NULL);
  
  fail_unless( List_countIf (NULL, NULL) == 0 );
  fail_unless( List_find (NULL, NULL, NULL) == NULL );
  fail_unless( List_findIf (NULL, NULL) == NULL );
  
  List_free(NULL);

  fail_unless( List_get (NULL, 0) == NULL );

  List_prepend(NULL, NULL);

  fail_unless( List_remove (NULL, 0) == NULL );
  fail_unless( List_size (NULL) == 0 );

}
Ejemplo n.º 4
0
void		List_insertion_sort(List *l, list_cmp_fct cmpf)
{
	List_Iterator	*it = FIRST(l);
	void *data = NULL;
	List_Iterator *current = NULL;
	List_Iterator *next = NULL;
	int len = COUNT(l);

	if (len <= 1 || !it)
		return ;
	INC_IT(it); //positioned on the second node
	while (it)
	{
		current = it;
		next = it->next;
		DEC_IT(it);
		while (it && cmpf(current->data, it->data) > 1)
			DEC_IT(it);
		if (!it) // prepend
		{
			data = List_remove_it(l, current); // Remove
			if (!List_prepend(l, data))
			{
				printf("Error prepending node to list [insertion sort]\n");
				return;
			}
		}
		else if (it != current && it != current->prev)
		{
			data = List_remove_it(l, current); // Remove
			if (!List_insert_after_it(l, it, data))
			{
				printf("Error inserting node into list [insertion sort]\n");
				return;
			}
		}
		it = next;
	}
}