Question: 2. Given two sorted lists , L1 and L2 , complete a following procedure in Java to compute: (a) L1 L2 = { x
2. Given two sorted lists, L1 and L2, complete a following procedure in Java to compute:
(a) L1 \ L2 = { x | x L1 and x L2 } using only the basic list operators (next(), hasNext(), and compareTo()) and one loop.
public static
void difference(List
{
ListIterator
ListIterator
if ( iterL1.hasNext() && iterL2.hasNext() )
{
itemL1 = iterL1.next();
itemL2 = iterL2.next();
}
// YOUR CODE GOES HERE
(b) L1 L2 = { x | x L1 and x L2 } using only the basic list operators (next(), hasNext(), and compareTo()) and one loop.
public static
void intersection(List
{
ListIterator
ListIterator
if ( iterL1.hasNext() && iterL2.hasNext() )
{
itemL1 = iterL1.next();
itemL2 = iterL2.next();
}
// YOUR CODE GOES HERE
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
