Type CTECList<Type>::removeEnd()
{

	assert(size > 0);

	ArrayNode<Type>* previous;
	ArrayNode<Type>* toDelete;
	ArrayNode<Type>* current = head;
	Type thing;

	if (current->getNext() == nullptr)
	{
		toDelete = current;
		thing = toDelete->getValue();
		delete toDelete;
		end = nullptr;
	}
	else
	{
		while(current->getNext() != nullptr)
		{
			previous = current;
			current = current->getNext();
		}
		toDelete = current;
		thing = toDelete->getValue();
		delete toDelete;
		previous->setNext() = nullptr;
		end = previous;
	}

	this->calculateSize();
	return thing;
}
Type CTECList<Type>::getAtIndex(int index)
{
	assert(index > size || index < 0);
	ArrayNode<Type>* current = head;

	for (int i = 0; i < index - 1; i++)
	{
		current = current->getNext();
	}

	return current->getValue();
}
Type CTECList<Type>::removeAtIndex(int index)
{
	ArrayNode<Type>* previous;
	ArrayNode<Type>* toDelete;
	ArrayNode<Type>* newNext;
	ArrayNode<Type>* current = head;
	Type thing;

	assert(this->size > 0);
	assert(index > 0 || index <= size);

	if (index == 0)
	{
		thing = removeFront();
	}
	else if (index == size - 1)
	{
		thing = removeEnd();
	}
	else
	{

		for (int i = 0; i < index; i++)
		{
			if (i == index - 1)
			{
				previous = current;
			}
			else if (i == index)
			{
				toDelete = current;
				thing = toDelete->getValue();
				newNext = current->getNext();
				delete toDelete;
				previous->setNext(newNext);
			}
			current = current->next();
		}
	}

	this->calculateSize();
	return thing;
}
Beispiel #4
0
int CTECArray<Type>::indexOf(Type searchValue)
{
	assert(this->size > 0);

	int indexNotFound = -1;

	ArrayNode<Type>* current = head;

	for(int index = 0; index < this->size; index++)
	{
		if(current->getValue() == searchValue)
		{
			return index;
		}
		else
		{
			current = current->getNext();
		}
	}
	return indexNotFound;
}