Question: Unsorted Linked List . A data structure of objects arranged in a linear order. The order is determined by a pointer in each object. This

Unsorted Linked List. A data structure of objects arranged in a linear order. The order is determined by a pointer in each object. This unsorted list must be implemented with pointers. You will then write a client code that will have a function that will take two unsorted lists and perform the union set operation. The resulting new unsorted list will consist of all the unique items from the original two lists with no duplicates.

  • Please read the question above and fix the problem. I tried but I couldn't, the following code is mine but it does not work. Please help me with this.

#include

struct NodeType; { ItemType info; NodeType* next;

class UnsortedType { public:

UnsortedType(); void MakeEmpty(); bool IsFull(); int GetLength(); ItemType GetItem(ItemType item, bool& found); void PutItem(ItemType item); void DeleteItem(ItemType item); void ResetList(); ItemType GetNextItem(); private:

NodeType* listData; int length; NodeType* currentPos; }

UnsortedType::UnsortedType() { length = 0;

void UnsortedType::InsertItem(ItemType item); { NodeType* location; location = new NodeType; location->info = item; location->next = listData; listData = location;

length++; } } bool UnsortedType::IsFull() { NodeType* location; { location = new NodeType; delete location; return false; } } int UnsortedType::GetLength()

{ return length; }

void UnsortedType::MakeEmpty() { NodeType* tempPtr; { while (listData != NULL) { tempPtr = listData; listData = listData->next; delete tempPtr; } length = 0; } }

ItemType UnsortedType::GetItem(ItemType item, bool& found)

{ bool moreToSearch; NodeType* location; location = listData; found = false; moreToSearch = (location !=NULL); while (moreToSearch && !found); { switch (item.ComparedTo(info[location])) { case LESS: case GREATER: location = location->next; moreToSearch = (location != NULL); break; case EQUAL: found = true; item = location->info; break; } } return item; }

UnsortedType::DeleteItem(ItemType item) { NodeType < ItemType* location = listData; NodeType* templocation;

if (item == listData->info) { tempLocation = location; listData = listData->next; } else {

while (item.ComparedTo(location->next)->info) != EQUAL) location = location->next;

tempLocation = location->next; location->next = (location->next)->next; }

} UnsortedType::ResetList() { currentPos = NULL; } ItemType UnsortedType::GetNextItem() { if (currentPos == NULL) currentPos = listData; else currentPos = currentPos->next; return currentPos->info; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!