Question: Note: Do display output of a running program Suppose we have a doubly linked list: 3, 1, 8, 5, 4, 2, 9, 6, 7, 0.
Note:
Do display output of a running program
Suppose we have a doubly linked list: 3, 1, 8, 5, 4, 2, 9, 6, 7, 0. Write a routine that swaps any two nodes in the list, resetting their forward and back pointers as needed. You should of course check that nodes a and b are in the list (however you like) and then exchange them in the list if both are present. Notice that the head pointer may change as a result of this operation. And remember to pay attention to the special cases, like: a and b are separated by one node in the list, a and b are adjacent to each other in the list, a or b is the head or the tail of the list. void swap(const node*& head_ptr, node*&a, node *& b) // up to you
Step by Step Solution
3.43 Rating (156 Votes )
There are 3 Steps involved in it
Answer A bool searchconst node headint key whileheadNULL ifheaddata ke... View full answer
Get step-by-step solutions from verified subject matter experts
