Select three methods in the object List class to work through algorithmically. D
ID: 3930648 • Letter: S
Question
Select three methods in the object List class to work through algorithmically. Describe any special cases or boundary conditions that might exist for each of the three methods selected. Be sure to draw pictures as you work through the methods. Remember that you cannot work on linked lists without drawing pictures. The homework will not be accepted without submitting the pictures! Write a java method with the signature: that accepts two unordered linear linked lists and returns a third linear linked list whose nodes contains the intersection of the original linear linked lists. Note that the intersection of two lists is a new list containing the elements that the two list have in common, without modifying the two original lists. Describe any boundary conditions that might exist.Explanation / Answer
publlic List intersect (List list1, List list2){
Map<Object,Integer> list1_map = new HashMap<Object,Integer>();
List list3 = new ArrayList();
for(Object obj : list1){
list1_map.put(obj,1);
}
for(Object obj2 : list2){
if(list1_map.get(obj2)!=null &&list1_map.get(obj2)==1){
list3.add(obj2);
list1_map.put(obj2,-1);
}
}
return list3;
}
//replace object with Integer/String according to requirement.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.