Question: mplement a (NON-RECURSIVE) method to find the common elements in two sorted linked lists, and return the common elements in sorted order in a NEW

mplement a (NON-RECURSIVE) method to find the common elements in two sorted linked lists, and return the common elements in sorted order in a NEW linked list. The original linked lists should not be modified. So, for instance,

 l1 = 3->9->12->15->21 l2 = 2->3->6->12->19 

should produce a new linked list:

 3->12 

You may assume that the original lists do not have any duplicate items.

Assuming an IntNode class defined like this:

 public class IntNode { public int data; public IntNode next; public IntNode(int data, IntNode next) { this.data = data; this.next = next; } public String toString() { return data + ""; } 

Complete the following method:

 // creates a new linked list consisting of the items common to the input lists // returns the front of this new linked list, null if there are no common items public IntNode commonElements(IntNode frontL1, IntNode frontL2) { ... } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!