Question: In a doubly linked list, write a program to switch two adjacent nodes pointed by p and q. (adjacent means p- RNext==q, q->LNext==p and we

In a doubly linked list, write a program to switch two adjacent nodes pointed by p and q. (adjacent means p- RNext==q, q->LNext==p and we assume that these two nodes are in the middle of the doubly linked list). The class definition is as follows: class DoublyLinkedList { private: int data; ListNode* LNext; //a pointer which points to the left neighbor ListNode* RNext; //a pointer which points to the right neighbor public: Swap(ListNode*, ListNode*); } DoublyLinkedList::Swap(ListNode* p, ListNode*
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
