Question: Use C++ The ADT UnsortedType List function DeleteItem(ItemType item) creates an endless loop error when trying to delete a word or key that is not
Use C++
The ADT UnsortedType List function DeleteItem(ItemType item) creates an endless loop error when trying to delete a word or key that is not in the list.
Example: Delete the word letter from the unsorted list.
Here are the lists contents before the DeleteItem(ItemType item) call:
super formula travel free thick Josephine Clara education
The question is how can I exit gracefully from the DeleteItem(itemType Item) call when the word or key is not in the unsorted list and not get an endless loop but instead printing out a message that the word letter is not in the loop? What code can be added?
void UnsortedType::DeleteItem(ItemType item)
{
NodeType* location;
NodeType* tempLocation;
location = listData;
if (item.ComparedTo(location->info) == EQUAL)
{
tempLocation = location;
listData = listData->next;
}
else
{
while (!((item.ComparedTo((location->next)->info) == EQUAL)))
location = location->next;
tempLocation = location->next;
location->next = (location->next)->next;
}
delete tempLocation;
length--;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
