Transcribed Image Text: Problem 1 (Graded) In chapter 1 you learned how to merge two sorted lists and get a third list which is also sorted. Write a method named mergeUnsorted Lists in an application, which given two unsorted lists list1 and list2, merge their nodes together to make one new list list3, by taking nodes alternately between the two lists. For example, if list! contains [1, 5, 3] and list2 contains [7, 13, 11, 8, 10 then they will be merged into list3 which would look like [1, 7, 5, 13, 3, 11, 8, 10]. Note that if either list (list) or list2) runs out of nodes, then all the nodes in the other list should be added to list3. Write a main method to test this method. The header of the method is given below. public static LinkedList mergeUnsortedLists (LinkedList listi, Linkedlist list2) { Problem 2 (Ungraded) Given the below Linked List named list1, show the content of the linked list result after the code is executed. list1 head 25 80 90 8 45 → 67 56 LinkedList result = new LinkedList(); Node curr = listi.getHead(); int i = 0; while (curr != null) { if (i82 == 0) result.addHead (curr.getData()); else result.addTail (curr.getData()); curr = curr.getNext(); i++; 1 The content of the linked list result is: Problem 3 (Ungraded) Given the below Linked List named list1, show the output of the below code fragment. list1 head 17 6 3085 25 → 51 34 Output Node curr - listi.getHead(); while (curr.getNext() != null) { System.out.println(curr.getData().getValue()); curr - curr.getNext().getNext();
More Transcribed Image Text: Problem 1 (Graded) In chapter 1 you learned how to merge two sorted lists and get a third list which is also sorted. Write a method named mergeUnsorted Lists in an application, which given two unsorted lists list1 and list2, merge their nodes together to make one new list list3, by taking nodes alternately between the two lists. For example, if list! contains [1, 5, 3] and list2 contains [7, 13, 11, 8, 10 then they will be merged into list3 which would look like [1, 7, 5, 13, 3, 11, 8, 10]. Note that if either list (list) or list2) runs out of nodes, then all the nodes in the other list should be added to list3. Write a main method to test this method. The header of the method is given below. public static LinkedList mergeUnsortedLists (LinkedList listi, Linkedlist list2) { Problem 2 (Ungraded) Given the below Linked List named list1, show the content of the linked list result after the code is executed. list1 head 25 80 90 8 45 → 67 56 LinkedList result = new LinkedList(); Node curr = listi.getHead(); int i = 0; while (curr != null) { if (i82 == 0) result.addHead (curr.getData()); else result.addTail (curr.getData()); curr = curr.getNext(); i++; 1 The content of the linked list result is: Problem 3 (Ungraded) Given the below Linked List named list1, show the output of the below code fragment. list1 head 17 6 3085 25 → 51 34 Output Node curr - listi.getHead(); while (curr.getNext() != null) { System.out.println(curr.getData().getValue()); curr - curr.getNext().getNext();