Question: Given two nonempty sorted lists , L1 and L2 . (a) Complete a following method in Java that prints true if L2 L1, and false
Given two nonempty sorted lists, L1 and L2.
(a) Complete a following method in Java that prints true if L2 L1, and false otherwise. In your implementation you can use only the basic list operators (next(), hasNext(), and compareTo()).
Remember that L2 L1 if for all x L2, x L1.
public static
boolean subset(List
{
ListIterator iterL1 = L1.listIterator();
ListIterator iterL2 = L2.listIterator();
// get first item in each list
if ( iterL1.hasNext() && iterL2.hasNext() )
{
itemL1 = iterL1.next();
itemL2 = iterL2.next();
}
// YOUR CODE GOES HERE
//
//
//
}
(b) What is the running time complexity of your method?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
