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
{
ListIterator
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
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