Question: Given two nonempty sorted lists , L1 and L2. (a) Complete a following method in Java that prints true if L2 L1, and false otherwise.

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 L1, List L2)

{

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

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!