In: Computer Science
**JAVA**
Create a Linked List and conduct the following operations. Portion of the program is given.
The operations are:
Partial program is:
import java.util.*;
public class LinkedListDemo{
public static void main(String[] args){
LinkedList <String> link = new LinkedList<String>();
link.add(" "); //add something here
link.add(" "); //add something here
System.out.println("The contents of array is" + link);
System.out.println("The size of an linkedlist is" + link.size());
//add your code
//end your code
}
}
Ans
code:-
import java.util.*;
public class LinkedListDemo{
public static void main(String[] args){
LinkedList <String> link = new LinkedList<String>();
link.add("H"); //add something here
link.add("I");
link.add("100");
//add something here
System.out.println("The contents of array is " + link);
System.out.println("The size of an linkedlist is " + link.size());
link.add(0,"H");//index 0 for beginning
link.add("R");//at end of list
System.out.println("The element at position 3 is: "+link.get(2));//get index 2
System.out.println("The last element is: "+link.get(link.size()-1));
link.add("U");
link.add("?");
link.remove(4);
System.out.println("The element at position 5 is: "+link.get(4));
System.out.println("The element popped at first place is: "+link.remove(0));
System.out.println("The contents of array is " + link);
System.out.println("The size of an linkedlist is " + link.size());
//add your code
//end your code
}
}
.
.
.
If any doubt ask in the comments.