list1, SingleLinkedList list2, int item)Example:Before Method call:item = 35list1:2326302017list2:109.25154.After Method call:list1:2326302017list2:101725174In this case,...


QUESTION 12<br>Write a method called CompareAndChangeList to be included in an application class called ListApplication that accepts two parameters list1 and list2 of type<br>SingleLinkedList of integer values, and a third parameter Item of type int. If list1 and list2 are of different sizes, the method returns false, otherwise, the method replaces<br>any element in list2 with a value equal to the last element in list1, if the summation of the element in list 1 and the corresponding element in list2 is equal to item. Assume list1<br>and list2 are not empty. If at least one replacement happened, the method returns true, otherwise, it returns false.<br>Note: Write this method by calling methods of the class SingleLinkedList.<br>Method head<br>public static boolean CompareAndChangeList (SingleLinkedList<Integer> list1, SingleLinkedList<Integer> list2, int item)<br>Example:<br>Before Method call:<br>item = 35<br>list1:<br>23<br>26<br>30<br>20<br>17<br>list2:<br>10<br>9.<br>25<br>15<br>4.<br>After Method call:<br>list1:<br>23<br>26<br>30<br>20<br>17<br>list2:<br>10<br>17<br>25<br>17<br>4<br>In this case, the method will return true<br>Note: as you can see the summation of 26 (in list 1) and its corresponding element (in list2) 9, is 35, which is equal to item, so we replace the element in list 2 (9) by the value of the last data in list1 which is<br>17. The same thing is between the elements 20 (in list 1) and 15 (in list 2). 15 is going to be replaced by 17. The rest will not change.<br>

Extracted text: QUESTION 12 Write a method called CompareAndChangeList to be included in an application class called ListApplication that accepts two parameters list1 and list2 of type SingleLinkedList of integer values, and a third parameter Item of type int. If list1 and list2 are of different sizes, the method returns false, otherwise, the method replaces any element in list2 with a value equal to the last element in list1, if the summation of the element in list 1 and the corresponding element in list2 is equal to item. Assume list1 and list2 are not empty. If at least one replacement happened, the method returns true, otherwise, it returns false. Note: Write this method by calling methods of the class SingleLinkedList. Method head public static boolean CompareAndChangeList (SingleLinkedList list1, SingleLinkedList list2, int item) Example: Before Method call: item = 35 list1: 23 26 30 20 17 list2: 10 9. 25 15 4. After Method call: list1: 23 26 30 20 17 list2: 10 17 25 17 4 In this case, the method will return true Note: as you can see the summation of 26 (in list 1) and its corresponding element (in list2) 9, is 35, which is equal to item, so we replace the element in list 2 (9) by the value of the last data in list1 which is 17. The same thing is between the elements 20 (in list 1) and 15 (in list 2). 15 is going to be replaced by 17. The rest will not change.
Jun 06, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here