Question: import java.util.LinkedList; public class LinkedListExample { public static void main ( String [ ] args ) { LinkedList first = new LinkedList ( ) ;

import java.util.LinkedList;
public class LinkedListExample {
public static void main(String[] args){
LinkedList first = new LinkedList ();
LinkedList second = new LinkedList();
// Add some numbers to the first list
first.addLast (4);
first.addFirst (9);
first.addLast (3);
first.addFirst (8);
first.addLast (11);
first.addFirst (5);
// A. Print the first list
System.out.println("first: "+ first);
// Add some numbers to the second list
for(int j=0;j2;j++)
second.add (j,2*(int) first.get (j)-1;
second.add ,(int) first.get (2-j)***(int) second.get (j);
}
// B. Print the second list
System.out.println("second: "+ second);
// Update the first list
update (first);
first.add (2,55);
first.add (2);
// C. Print the updated first list
System.out.println("first: "+ first);
// Update the second list
second.addFirst (second.removelast ());
// D. Print the updated second list
System.out.println("second: "+ second);
}
public static void update(LinkedList list){
for(int j=1;j list.size(); j++)
if (list.contains (j))
list.remove (j);
}
}
OUTPUT
 import java.util.LinkedList; public class LinkedListExample { public static void main(String[] args){

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!