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

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!