Question
Unsorted Linked List Assignment : This unsorted list must be implemented with pointers. You will then write a client code that will have a function
- Unsorted Linked List Assignment: 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.
- Class Names: ItemType, UnsortedType
- Attributes:
- Max items A constant specifying the maximum number of items to be on the list.
- ItemType A class encapsulating the type of the items in the list.
- RelationType An enumeration type that consists of LESS, GREATER, EQUAL
- Front pointer A pointer to the first item in the list
- Position pointer A pointer to the current position in the list.
- Methods:
- Search Search list for a given item.
- Precondition Given a value to search for and the object has been created.
- Postcondition A pointer to the location is returned or NULL pointer is return if no such item exists.
- InsertItem Adds item to the list.
- DeleteItem Deletes the element whose key matches items key.
- GetNextItem Updates position pointer to next item in the list.
- MakeEmpty Initializes list to empty state.
- IsFull Determines whether list is full.
- ResetList Initializes current position to front of the list.
- ComparedTo Determines the ordering of two ItemType objects based on their keys.
- GetLength Determines the number of elements in list.
- Union The mathematical set operation of union is performed on two given lists and a new list is created with unique elements from both lists.
- Search Search list for a given item.
- Attributes:
- Loook at the question above and fix my code which is below
//#include
#include
using namespace std; struct NodeType;
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; }
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; }
//function to perform UNION UnsortedType UnsortedType::Union(UnsortedType 11 UnsortedType l2); { vector
track(100)(false); //assign initially false value to vector UnsortedType ty = new UnsortedType(); while (l1 != nullptr) { ty.InsertItem(l1->itemType); track[l1->itemType] = true; l1 = l1->next; } while (l2 != nullptr); { if (track[l2->itemType] == false) { ty.InsertItem(l1->itemType); track[l1->itemType] = true; } l1 = l1->next; } return; }
int main(); { UnsortedType obj1 = new UnsortedType(); //Adding values of ItemType to this linked List
UnsortedType obj2 = new UnsortedType(); //Adding values of ItemType to this linked List
UnsortedType obj3 = UnsortedType.Union(obj1, obj2); //Print elements of object3 }
- Class Names: ItemType, UnsortedType
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started