Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

2nd Edition

1597499471, 978-1597499477

More Books

Students also viewed these Databases questions

Question

What are financial assets and financial liabilities?

Answered: 1 week ago

Question

Describe effectiveness of reading at night?

Answered: 1 week ago

Question

find all matrices A (a) A = 13 (b) A + A = 213

Answered: 1 week ago

Question

Why could the Robert Bosch approach make sense to the company?

Answered: 1 week ago