Question: Presentation exercise 3 Write a static method to be added to the SLinkedList class you have seen in the pre-recorded lectures. The method is called


Presentation exercise 3 Write a static method to be added to the SLinkedList class you have seen in the pre-recorded lectures. The method is called get_intersection() and it takes two singly linked list as input. The method returns a singly linked list representing the intersection of the two input lists. If the two input lists do not intersect, then the method returns an empty list. Note that we say that two lists intersect when they have at least one node in common. The intersection is defined base on reference, not on value! The node needs to be exactly the same node, and not only contain the same value. This method should run in O(max(n, m)) where n and m represents the number of elements of the input lists. SINGLY LINKED LIST public class SLinkedList { private SNode head; private SNode tail; private int size; head : tail list size 4 private class SNode { Shape element; SNode next; } } null SLinkedList list = new SLinkedlist(); Presentation exercise 3 Write a static method to be added to the SLinkedList class you have seen in the pre-recorded lectures. The method is called get_intersection() and it takes two singly linked list as input. The method returns a singly linked list representing the intersection of the two input lists. If the two input lists do not intersect, then the method returns an empty list. Note that we say that two lists intersect when they have at least one node in common. The intersection is defined base on reference, not on value! The node needs to be exactly the same node, and not only contain the same value. This method should run in O(max(n, m)) where n and m represents the number of elements of the input lists. SINGLY LINKED LIST public class SLinkedList { private SNode head; private SNode tail; private int size; head : tail list size 4 private class SNode { Shape element; SNode next; } } null SLinkedList list = new SLinkedlist()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
