@@ -0,0 +1,2038 @@
+package data_structures.linked_lists;%0D%0A%0D%0Aimport java.util.*;%0D%0A%0D%0A/*%0D%0A * Problem Statement:%0D%0A * Youre given the pointer to the head nodes of two sorted linked lists. The%0D%0A * data in both lists will be sorted in ascending order. Change the next%0D%0A * pointers to obtain a single, merged linked list which also has data in%0D%0A * ascending order. Either head pointer given may be null meaning that the%0D%0A * corresponding list is empty.%0D%0A * %0D%0A * Input Format:%0D%0A * You have to complete the Node* MergeLists(Node* headA, Node* headB) method%0D%0A * which takes two arguments - the heads of the two sorted linked lists to%0D%0A * merge. You should NOT read any input from stdin/console.%0D%0A * %0D%0A * Output Format:%0D%0A * Change the next pointer of individual nodes so that nodes from both lists are%0D%0A * merged into a single list. Then return the head of this merged list. Do NOT%0D%0A * print anything to stdout/console.%0D%0A * %0D%0A * Sample Input: %0D%0A * 1 -%3E 3 -%3E 5 -%3E 6 -%3E NULL%0D%0A * 2 -%3E 4 -%3E 7 -%3E NULL%0D%0A * %0D%0A * 15 -%3E NULL%0D%0A * 12 -%3E NULL%0D%0A * %0D%0A * NULL%0D%0A * 1 -%3E 2 -%3E NULL%0D%0A * %0D%0A * Sample Output: %0D%0A * 1 -%3E 2 -%3E 3 -%3E 4 -%3E 5 -%3E 6 -%3E 7%0D%0A * 12 -%3E 15 -%3E NULL%0D%0A * 1 -%3E 2 -%3E NULL%0D%0A */%0D%0Apublic class MergeTwoSortedLinkedLists %7B%0D%0A%0D%0A%09Node MergeLists(Node headA, Node headB) %7B%0D%0A%0D%0A%09    Node runnerA = headA;%0D%0A%09    Node runnerB = headB;%0D%0A%09 %0D%0A%09    ArrayList%3CInteger%3E arrayA = new ArrayList%3C%3E();%0D%0A%09    ArrayList%3CInteger%3E arrayB = new ArrayList%3C%3E();%0D%0A%09    %0D%0A%09    while (runnerA != null) %7B%0D%0A%09        arrayA.add(runnerA.data);%0D%0A%09        runnerA = runnerA.next;%0D%0A%09    %7D%0D%0A%09    %0D%0A%09    while (runnerB != null) %7B%0D%0A%09        arrayB.add(runnerB.data);%0D%0A%09        runnerB = runnerB.next;%0D%0A%09    %7D%0D%0A%09    %0D%0A%09    arrayA.addAll(arrayB);%0D%0A%09    Collections.sort(arrayA);%0D%0A%09    %0D%0A%09    Node head = new Node();%0D%0A%09    head.data = arrayA.get(0);%0D%0A%09    %0D%0A%09    Node runner = head;%0D%0A%09    %0D%0A%09    for (int i = 1; i %3C arrayA.size(); i++) %7B%0D%0A%09        Node newNode = new Node();%0D%0A%09        newNode.data = arrayA.get(i);%0D%0A%09        runner.next = newNode;%0D%0A%09        runner = runner.next;%0D%0A%09    %7D%0D%0A%09    %0D%0A%09    return head;%0D%0A%09%7D%0D%0A%7D

Add MergeTwoSortedLinkedLists