Question: C++ : Move the first two nodes to the end of the calling object. This will require resetting the pointer ptrToFirst, and last if it

C++ : Move the first two nodes to the end of the calling object. This will require resetting the pointer ptrToFirst, and last if it is a doubly-linked list, and all other necessary pointers to connect the list.

Need both Singly-linked and doubly-linked lists code.

DO not use NULL, use nullptr instead.

There are no parameters.

C++ : Move the first two nodes to the end of the

calling object. This will require resetting the pointer ptrToFirst, and last if

#ifndef ANYLIST_H #define ANYLIST_H #include #include // Need to include for nullptr. class Node { public: Node() : data(), ptrToNext(nullptr) {} Node(int theData, Node *newPtrToNext) : data(theData), ptrtoNext(newPtrToNext){} Node* getPtrToNext() const { return ptrToNext; } int getData() const { return data; } void setData(int theData) { data = theData; } void setPtrToNext (Node *newPtrToNext) { ptrToNext = newPtrToNext; } Node(){} private: int data; Node *ptrToNext; // Pointer that points to next node. }; class AnyList {l public: AnyList(): ptr ToFirst(nullptr), count() {} void print() const; void clearlist(); AnyList(); private: Node *ptrToFirst; // Pointer to point to the first node in the list. int count; // Variable to keep track of number of nodes in the list. }; #endif #ifndef DOUBLYLIS #define DOUBLYLIST_H #include #include class Node { public: Node() : data(), prev(nullptr), next(nullptr) {} Node(int theData, Node* prevLink, Node* nextLink) data(theData), prev(prevlink), next(nextLink) {} int getData() const { return data; } Node* getPrev() const { return prev; } Node* getNext() const { return next; } void setData(int theData) { data = theData; } void setPrev(Node prevlink) { prev = prevlink; } void setNext(Node nextLink) { next = nextLink; } Node(){} private: int data; // to simplify, we are using only one piece of data. Node* prev; Node* next; }; class DoublyList { public: DoublyList() : first(nullptr), last(nullptr), count() {} void insertFront(int newData void clearlist(); DoublyList(); private: // Pointer to the first node on the list. Node *first; // Pointer to the Last node on the list. Node *last; // Number of nodes in the list. int count; }; #endif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!