Question
Linked list implementation of Unsorted List is given below. Draw the linked list picture for the function calls given below. UnsortedType list; List.PutItem(26); List.PutItem(56); List.PutItem(16);
Linked list implementation of Unsorted List is given below. Draw the linked list picture for the function calls given below.
UnsortedType list;
List.PutItem(26);
List.PutItem(56);
List.PutItem(16);
List.DeleteItem(26)
; List.PutItem(66);
Show picture of linked list after each function call // This file contains the linked implementation of class // UnsortedType. #include "unsorted.h" struct NodeType { ItemType info; NodeType* next; }; UnsortedType::UnsortedType() // Class constructor { length = 0; listData = NULL; } void UnsortedType::PutItem(ItemType item) // item is in the list; length has been incremented. { NodeType* location; // Declare a pointer to a node location = new NodeType; // Get a new node location->info = item; // Store the item in the node location->next = listData; // Store address of first node // in next field of new node listData = location; // Store address of new node into // external pointer length++; // Increment length of the list } void UnsortedType::DeleteItem(ItemType item) // Pre: item's key has been initialized. // An element in the list has a key that matches item's. // Post: No element in the list has a key that matches item's. { NodeType* location = listData; NodeType* tempLocation; // Locate node to be deleted. if (item.ComparedTo(listData->info) == EQUAL) { tempLocation = location; listData = listData->next; // Delete first node. } else { while (item.ComparedTo((location->next)->info) != EQUAL) location = location->next; // Delete node at location->next tempLocation = location->next; location->next = (location->next)->next; } delete tempLocation; length--; }
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