Assume thát the following method is in a class called DLL (not s ame as KWLinkedList). What does this method do? public void method_LI( ) { KWLinkedList list = new KWLinkedList( ); list.add(2); list.add(-1); list.add(0); list.add(1); list.add(0); Listlterator iter = list.listiterator(); while(iter.hasNext()) { if (iter.next() 0) == iter.remove(); } if( iter.hasPrevious()) System.out.println("END"); else while(iter.hasNext()) System.out.print(iter.next() + " "); }
java program :
Assume that the following method is in a class called DLL (not same as KWLinkedList). What does this method do?
public void method_LI( )
{
KWLinkedList<Integer> list = new KWLinkedList<Integer>( );
list.add(2);
list.add(-1);
list.add(0);
list.add(1);
list.add(0);
ListIterator<integer> iter = list.listIterator();
while(iter.hasNext())
{
if (iter.next() == 0)
iter.remove();
}
if( iter.hasPrevious() )
System.out.println("END");
else
while(iter.hasNext())
System.out.print(iter.next() + " ");
}
-
Removes the nodes having 0 as its data and prints 2 -1 1
-
Prints 2 -1 0 1 0 without removing anything.
-
Removes the nodes having 0 as its data and prints END.
-
Removes the nodes having 0 as its data and prints 1 -1 2
Step by step
Solved in 2 steps