DoublyList.cpp: #include "DoublyList.h" using namespace std; 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; } void DoublyList::printForward() const { DLLNode* current = first; while (current != nullptr) { cout << current->getData() << " "; current = current->getNext(); } } void DoublyList::printReverse() const { DLLNode* current = last; while (current != nullptr) { cout << current->getData() << " "; current = current->getPrev(); } } void DoublyList::clearList() { DLLNode* temp = first; while (first != nullptr) { first = first->getNext(); delete temp; temp = first; } last = nullptr; // Don't forget to reset pointer last to nullptr. count = 0; } DoublyList::~DoublyList() { if (first != nullptr) clearList(); } DoublyList.h #ifndef DOUBLYLIST_H #define DOUBLYLIST_H #include <string> #include <iostream> 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 rotateNodesRight(int); 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 Main.cpp #include "DoublyList.h" #include <iostream> #include <vector> using namespace std; int main() { vector<vector<int>> data = { {25, 76, 35, 67, 15, 98}, {1, 2, 3, 4, 5, 6, 7, 8, 9}, {10, 20}, {34, 56, 78, 12, 89, 34, 76, 28, 54, 22, 41}, {123, 873, 619}, }; vector<int> nodesToRotate = { 2, 3, 1, 9, 2 }; { DoublyList doublyList; int vectorSize = static_cast<int>(data.size()); for (int i = 0; i < vectorSize; ++i) { int innerSize = static_cast<int>(data[i].size()); for (int j = innerSize - 1; j >= 0; --j) doublyList.insertFront(data[i].at(j)); cout << "Rotate right: " << nodesToRotate[i] << "\n"; cout << " List is: "; doublyList.printForward(); cout << "\n"; doublyList.rotateNodesRight(nodesToRotate[i]); cout << "After rotating:"; cout << "\n Print forward: "; doublyList.printForward(); cout << "\nPrint backwards: "; doublyList.printReverse(.