Answered step by step
Verified Expert Solution
Question
1 Approved Answer
class CDLinkedList { public: CDLinkedList ( ) ; / / the constructor CDLinkedList ( const CDLinkedList &rhs ) ; ~CDLinkedList ( ) ; / /
class CDLinkedList
public:
CDLinkedList; the constructor
CDLinkedListconst CDLinkedList &rhs;
~CDLinkedList; the destructor
int getCurrentSize const;
bool isEmpty const;
bool addint newEntry;
bool removeint anEntry;
void clear;
This will search the entry from the list. make sure to use virtual so that transposelist can override
virtual bool containsint anEntry;
int getTraverseCount const; return traverseCount
int retrieve const int index ; retrieve the data by index. The first item is at index
void resetTraverseCount traverseCount ;
protected:
DListNode header; a dummy header
int traverseCount ;
;
The data member traverseCount is initialized to zero and is used to hold the count of the number of nodes traversed during list usage. contains remove and retrieve methods should update this count as it traverses the list ie increment it each time it moves from one Node to the next add method will add a Node in front if the data is not already in the list. If it is already in the list, then ignore. Since it also traverses the list, this add method should also update the traverse count. If add method calls containsmethod it will automatically update the traverse count. If not, you have to make sure to update the traverse count in the method as well. It is up to your design.
Make two subclasses of CDLinkedList called MtfList and TransposeList, that implements the movetofront and swap strategy, respectively, by overriding CDLinkedList ::contains method. MtfList ::contains should override CDLinkedList ::contains method so that if it contains, move the target node to front. TransposeList ::contains should override CDLinkedList ::contains method so that if it contains, swap the target node with the previous node.
Test each class's method with your own designed testing file. A brief sample driver.cpp file is available from FilesProgramsprogram folder. The following testing scenarios explain how to test your programs.
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