2. Given two sorted lists , L1 and L2 , complete a following procedure in Java to...
Question:
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
Data Structures and Algorithm Analysis in Java
ISBN: 978-0132576277
3rd edition
Authors: Mark A. Weiss