Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started