Question
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
header = new DListNode
header->next = NULL;
header->prev = NULL;
cost = 0;
}
int TransposeList
DListNode
int i = 0;
for ( ; found != NULL && found->item != obj; found = found->next, ++i )
++DList
if ( found == NULL )
return -1;
if ( found == DList
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
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