Use C++ 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 /* This is a C++ program to merge two sorted linked lists and produce a list in a Sorted order */ #include #include #include /* Link list node */ struct node { int data; struct node* next; }; /* This function is used to pull off the front node of the source and put it in destnation */ void letusMoveNode(struct node** destRef, struct node** sourceRef); /* This is a function used for performing merging of two linked lists.It takes two lists sorted in increasing order, and splices their nodes together to make one big sorted list which is returned. */ struct node* letssortlists(struct node* a, struct node* b) { /* Let us first have dummyone first node to hang the result on */ struct node dummyone; /*next the tail points to the last result node */ struct node* tail = &dummyone; /* As a result, tail->next is the place to add new nodes to the result. */ dummyone.next = NULL; while (1) { if (a == NULL) { /*we will check that if either list runs out, use the other list */ tail->next = b; break; } else if (b == NULL) { tail->next = a; break; } if (a->data <= b->data) letusMoveNode(&(tail->next), &a); else letusMoveNode(&(tail->next), &b); tail = tail->next; } return(dummyone.next); } /* letusMoveNode() function is a function which takes the node from the front of the source, and move it to the front of the dest. Before calling letusMoveNode(): source == {1, 2, 3} dest == {1, 2, 3} Affter calling letusMoveNode(): source == {3, 4} dest == {1, 2, 3, 4} */ void letusMoveNode(struct node** destReference, struct node** sourceReference) { /*This is the front source node */ struct node* newNode = *sourceReference; assert(newNode != NULL); /* now we will advance the source pointer */ *sourceReference = newNode->next; /*next we will link the old dest off the new node */ newNode->next = *destReference; /* Fineally we will move dest to point to the new node */ *destReference = newNode; } /* This IS A function which is used to insert a node at the beginning of the linked list */ void insertpush(struct node** head_reference, int new_data) { /* This is used to allocate node */ struct node* new_node = (struct node*) malloc(sizeof(struct node)); /* now we will put in the data */ new_node->data = new_data; /* The next step is to link the old list off the new node */ new_node->next = (*head_reference); /*Finally we will move the head to point to the new node */ (*head_reference) = new_node; } /* This is a function to print nodes in a given linked list */ void printList(struct node *node) { while (node!=NULL) { printf(\"%d \", node->data); node = node->next; } } /*This is the driver program to test ab.