[SOLVED] Solved:  ListIterator

15.00 $

Programming resource
Digital learning resource
Category:
Practical programming resource
Suitable for guided study and reference
Tutor guidance available when needed

Description

5/5 - (1 vote)

Given two nonempty sorted lists, L1 and L2.

(a) 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 <AnyType extends Comparable<? super AnyType>>

boolean subset(List<AnyType> L1, List<AnyType> L2)

{

ListIterator<AnyType> iterL1 = L1.listIterator();

ListIterator<AnyType> 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?

Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.