Write a function to merge two doubly linked lists. The input lists have their elements in sorted order, from lowest to highest. The output list should also be sorted from lowest to highest. Your algorithm should run in linear time on the length of the output list. Provide an algorithm for your function Implement and show some samples of your running function Solution The algorithm for LinkedList MergeSort is as follows. The trick in this algorithm is to use a local list to store the value which is pointing to the actual list to be returned as a result of the function Step1: START Step2: GET inputs of list1 and list2 Step3: INITIALIZE mergelist STEP4: SET mylist = mergelist Step5: WHILE list1 OR list2 is EMPTY DO IF (list1 AND list2) are NOT EMPTY IF list1.value > list2.value mylist.next = list2 ELSE mylist.next = list1 ELSE IF list1 is EMPTY mylist.next = list2 ELSE mylist.next = list1 Step6: RETURN mergelist Step7: STOP Sample program for the same implemented in C++ //==================================================================== ======== // Name : DoublyLinkedList.cpp // Author : Kaju // Version : 0.1 // Copyright : This is just an example code // Description : MergeSort in C++, Ansi-style //==================================================================== ======== /* * C++ Program to Implement Doubly Linked List */ #include #include #include /* * Node Declaration */ using namespace std; // struct declaration for node which will hold the integer data with links to previous data and next data struct node { int data; struct node *next; struct node *prev; }; /* Class Declaration */ class DoublyLinkedList { private: struct node *start; // collection of all the nodes public: void create(int value); int peek(); int delete_head(); void display(); int count(); void mergeSort(DoublyLinkedList list1, DoublyLinkedList list2); DoublyLinkedList() { start = NULL; } }; /* * Add data into the list */ void DoublyLinkedList::create(int value) { struct node *s, *temp; temp = new(struct node); temp->data = value; temp->next = NULL; if (start == NULL) { temp->prev = NULL; start = temp; } else { s = start; while (s->next != NULL) s = s->next; s->next = temp; temp->prev = s; } } /* * Deletion of the first element from the list * store the first element in a temp node and then remove it from start. */ int DoublyLinkedList::delete_head() { struct node *tmp, *q; int value; tmp = start; if(start->next!=NULL) { start = start->next; start->prev = NULL; } else start = NULL; value = tmp->data; free(tmp); return value; } /* * return the first element of Doubly Link List */ int DoublyLinkedList::peek() { struct node *q; if (start == NULL) { cout<<\"List is empty\"<data; } } /* * Display elements of Doubly Link List */ void DoublyLinkedList::display() { struct node *q; if (start == NULL) { cout<<\"List is empty\"<data; q = q->next; if(q != NULL) { cout<<\", \"; } } cout<<\"]\"<next; cnt++; } return cnt; } /* * MergeSort - takes two input lists and then based on the.