Select three methods in the ObjectList class to work through
Solution
Node.java
//Defines each node of a linked list
public class Node{
     int data;
     Node next;
     Node(int d)
     {
         data = d;
         next = null;
     }
 }
ObjectList.java
public class ObjectList{
     public Node head;
    /* Utility function to print list */
     public void printList()
     {
         Node temp = head;
         while(temp != null)
         {
             System.out.print(temp.data+\" \");
             temp = temp.next;
         }
         System.out.println();
     }
     /* Inserts a node at start of linked list */
     public void push(int new_data)
     {
         /* 1 & 2: Allocate the Node &
                   Put in the data*/
         Node new_node = new Node(new_data);
        /* 3. Make next of new Node as head */
         new_node.next = head;
        /* 4. Move the head to point to new Node */
         head = new_node;
     }
     /* A utilty function that returns true if data is present
        in linked list else return false */
     public boolean isPresent (int data){
         Node t = this.head;
         while (t != null)
         {
             if (t.data == data)
                 return true;
             t = t.next;
         }
         return false;
     }
 }
Intersection.java
//Implements the intersection method.
class Intersection{
    static public ObjectList intersect(ObjectList list1, ObjectList list2){
         ObjectList result = new ObjectList();
         //Node t1 = head1;
         Node t1 = list1.head;
         Node t2 = list2.head;
         // Traverse list1 and search each element of it in list2.
         // If the element is present in list 2, then insert the
         // element to result
         while (t1 != null){
             if (list2.isPresent(t1.data))
                 result.push(t1.data);
             t1 = t1.next;
         }
         return result;
     }
    /* Driver program to test above functions */
     public static void main(String args[]){
        ObjectList llist1 = new ObjectList();
         ObjectList llist2 = new ObjectList();
         ObjectList unin = new ObjectList();
         ObjectList intersecn = new ObjectList();
        /*create a linked lits 10->15->5->20 */
         llist1.push(20);
         llist1.push(4);
         llist1.push(15);
         llist1.push(10);
        /*create a linked lits 8->4->2->10 */
         llist2.push(10);
         llist2.push(2);
         llist2.push(4);
         llist2.push(8);
        intersecn = intersect(llist1, llist2);
         intersecn.printList();
    }
 }


