Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions