Exemple #1
0
int testLinkedList(void) {
	Node *headAndTail[2];	
	headAndTail[0] = NULL; //head
	headAndTail[1] = NULL; //tail

	printf("Start Test of Linked List.\n");
	printf("Initial contents of the list:\n");
	printList(headAndTail[0]);

	printf("\naddToEnd() 2, 3 and 7 to an empty list\n");
	addToEnd(headAndTail, 2);
	printList(headAndTail[0]);
	addToEnd(headAndTail, 3);
	printList(headAndTail[0]);
	addToEnd(headAndTail, 7);
	printList(headAndTail[0]);

	printf("\nremoveFromEnd() three times to make the list empty again\n");
	removeFromEnd(headAndTail);
	printList(headAndTail[0]);
	removeFromEnd(headAndTail);
	printList(headAndTail[0]);
	removeFromEnd(headAndTail);
	printList(headAndTail[0]);

	printf("\naddToStart() 2, 3 and 7 to an empty list\n");
	addToStart(headAndTail, 2);
	printList(headAndTail[0]);
	addToStart(headAndTail, 3);
	printList(headAndTail[0]);
	addToStart(headAndTail, 7);
	printList(headAndTail[0]);

	printf("\nremoveFromStart() three times to make the list empty again\n");
	removeFromStart(headAndTail);
	printList(headAndTail[0]);
	removeFromStart(headAndTail);
	printList(headAndTail[0]);
	removeFromStart(headAndTail);
	printList(headAndTail[0]);

	printf("\n Test error handling: removeFromEnd() and removeFromStart() on empty list\n");
	removeFromEnd(headAndTail);
	removeFromStart(headAndTail);
	printf("\n Testing Completed - No Errors\n");

	return EXIT_SUCCESS;
}
Type CTECList<Type>:: removeFromIndex(int index)
{
	Type thingToRemove;

	assert(size > 0);
	assert(index >= 0);
	assert(index < size);
	assert(size > 0 && index >= 0 && index < size); //Same as the three above

	ArrayNode<Type> * previous, deleteMe, newNext;
	if(index == 0)
	{
		thingToRemove = removeFromFront();
	}
	else if(index == size - 1)
	{
		thingToRemove = removeFromEnd();
	}
	else
	{
		for(int spot = 0; spot < index + 1; spot++)
		{

		}
	}

	this -> calculateSize();
	return thingToRemove;
}
Type CTECList<Type> :: removeFromIndex(int index)
{
    assert(this->size > 0);
    assert(index >= 0 && index < size);
    Type thingToRemove;
    Arraynode<Type> * previous,deleteMe,newNext;

    if(index == 0)
    {
        thingToRemove = removeFromFront();
    }
    else if(index == size-1)
    {
        thingToRemove = removeFromEnd();
        p
    }
Exemple #4
0
Type CTECList<Type>::removeFromIndex(int index)
{

	assert(index >= 0);
	assert(index < size);
	assert(size > 0);
	ArrayNode<Type> * deleteMe = new ArrayNode<Type>();
	Type thingToRemove;
	ArrayNode<Type> * newNext = new ArrayNode<Type>();
	ArrayNode<Type> * current = new ArrayNode<Type>();
	ArrayNode<Type> * previous = new ArrayNode<Type>();

	if(index == 0)
	{

		thingToRemove = removeFromFront();
	}

	else if(index == size-1)
	{
		thingToRemove = removeFromEnd();
	}
	else

	{


		for(int index = 0; index < size  ; index++)
		{

			current = current->next();

		}
		ArrayNode<Type> * previous = newNext;
		delete deleteMe;
		this->calculateSize;
		return deleteMe;
	}
}