Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Q2 [15 marks] Write a C++ code of a function called DeleteItem) of the UnsortedT

ID: 3600221 • Letter: Q

Question

Q2 [15 marks] Write a C++ code of a function called DeleteItem) of the UnsortedType class using the array based implementation to perform a conditional delete. The delete is only to be made if an item with the same key exists in the list. A boolean reference parameter, ItemExists, is set to indicate if the item is already in the list. You are given below the Deleteltem method of the UnsoctedType class without the conditional delete void UnsoxtedTypeDeletltem dtemTvps item)t int location 0 while (item list[location]) location++ list [location]= list [size-1]; size-

Explanation / Answer

THe Answer for your question is given below clearly:

code:

#include "UnsortedType.h"
#include <iostream>
using namespace std;

UnsortedType::UnsortedType() //constructor
{
length = 0;
listData = NULL;
}

UnsortedType::~UnsortedType() //destructor
{
NodeType* tempPtr;

// Loop removes all nodes from list
// deallocating space for each one
while(listData != NULL)
{
tempPtr = listData;
listData = listData->next;
delete tempPtr;
}
}


void UnsortedType::DeleteItem(ItemType item) //delete method done as per the requirement
{
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--;
}


Hope This Helps, if you have any doubts Please comment i will get back to you, thank you and please thumbs up