Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++, you need to transpose the linked list, where you move the object in the node that is being searched, one node closer to

In C++, you need to transpose the linked list, where you move the object in the node that is being searched, one node closer to the head. This allows to decrease the cost as the more often the obj is searched the closer it moves to the head of the list. You have a remove function to remove the node from the linked list. You need to create add to the find function where the parameter is the object that is being searched and will be swapped one node closer to the head. Insert your line of code in the find function where the two helper comments are at the end of the find function.

DList::DList( ) {

header = new DListNode;

header->next = NULL;

header->prev = NULL;

cost = 0;

}

int TransposeList::find( const Object &obj ) {

DListNode *found = DList::header->next;

int i = 0;

for ( ; found != NULL && found->item != obj; found = found->next, ++i )

++DList::cost;

if ( found == NULL )

return -1;

if ( found == DList::header->next )

return 0;

// remove found from the current position

// insert found before previous

}

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

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

Students also viewed these Databases questions

Question

m Have you chosen the most effective organizational plan?

Answered: 1 week ago