Question: /////////////////////////////////////////////////////////////////////////HEADER/////////////////////////////////////////////////////////////////////////////////////////////////////////////// //HEADERFILE// #ifndef DOUBLYLIST_H #define DOUBLYLIST_H #include #include class DLLNode { public: DLLNode() : data(0), prev(nullptr), next(nullptr) {} DLLNode(int theData, DLLNode* prevLink, DLLNode* nextLink) :
/////////////////////////////////////////////////////////////////////////HEADER///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//HEADERFILE//
#ifndef DOUBLYLIST_H #define DOUBLYLIST_H
#include
class DLLNode { public: DLLNode() : data(0), prev(nullptr), next(nullptr) {} DLLNode(int theData, DLLNode* prevLink, DLLNode* nextLink) : data(theData), prev(prevLink), next(nextLink) {} int getData() const { return data; } DLLNode* getPrev() const { return prev; } DLLNode* getNext() const { return next; } void setData(int theData) { data = theData; } void setPrev(DLLNode* prevLink) { prev = prevLink; } void setNext(DLLNode* nextLink) { next = nextLink; } ~DLLNode(){} private: int data; // To simplify, we are using only one piece of data. DLLNode* prev; DLLNode* next; };
class DoublyList { public: DoublyList() : first(nullptr), last(nullptr), count(0) {}
void insertFront(int newData);
void printForward() const; void printReverse() const; void selectSuitor(); void clearList(); ~DoublyList();
private: // Pointer to the first node in the list. DLLNode*first; // Pointer to the last node in the list. DLLNode*last; // Number of nodes in the list. int count; };
#endif
//////////////////////////////////////////////////////////////////////////////////////////////////////////cpp/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CPP>FILE///// solution with selectSuitor()
void DoublyList::insertFront(int newData) { if (first == nullptr) { first = new DLLNode(newData, nullptr, nullptr); last = first; // Common error: Forgetting to reset pointer last. } else { first = new DLLNode(newData, nullptr, first); first->getNext()->setPrev(first); // Common error: Forgetting to connect pointer // prev of what is now the second node to the // new first node. }
++count; }
//your solution for with selectSuitor()
void DoublyList::selectSuitor() { first -> setPrev(last); last -> setNext(first); DLLNode *current = first; DLLNode *tail = first; cout 1) { current = current -> getNext() -> getNext(); tail = current -> getNext(); current -> getPrev() -> setNext(current -> getNext()); current -> getNext() -> setPrev(current -> getPrev()); current -> setPrev(nullptr); current -> setNext(nullptr); cout getData() 2) { delete current; current = tail; } --count; }
first = current; last = current;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////MAIN/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
MAIN FILE/////
#include "DoublyList.h"
#include
using namespace std;
int main() { DoublyList intList; intList.insertFront(6); intList.insertFront(5); intList.insertFront(4); intList.insertFront(3); intList.insertFront(2); intList.insertFront(1);
intList.selectSuitor();
return 0; }
:- the expected output with multiple test is failing please help>
MY OUTPUT EXPECTED OUTPUT

Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
