Question

In: Computer Science

**JAVA** Create a Linked List and conduct the following operations. Portion of the program is given....

**JAVA**

Create a Linked List and conduct the following operations. Portion of the program is given.

The operations are:

  1. Add an “H” to the list
  2. Add an “I” to the list
  3. Add “100” to the list
  4. Print the content of the list and its size
  5. Add a “H” to the first place of the list
  6. Add a “R” to the last place of the list
  7. Get the element of position 3 and print it
  8. Get the last element and print it
  9. Add an “U” to the list
  10. Add a “?” to the list
  11. Remove the element of position 5
  12. Get and print the element of position 5
  13. Remove the element of first place and print the element
  14. Print the content of the list and its size

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

}

}

Solutions

Expert Solution

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.


Related Solutions

Create a Linked List and conduct the following operations. Portion of the program is given. The...
Create a Linked List and conduct the following operations. Portion of the program is given. The operations are: Add an “H” to the list Add an “I” to the list Add 100 to the list Print the content of the list and its size Add a “H” to the first place of the list Add a “R” to the last place of the list Get the element of position 3 and print it Get the last element and print it...
Using Linked List, create a Java program that does the following without using LinkedList from the...
Using Linked List, create a Java program that does the following without using LinkedList from the Java Library. and please include methods for each function. Create a menu that contains the following options : 1. Add new node at the end of LL. ( as a METHOD ) 2. Add new node at the beginning of LL. ( as a METHOD ) 3. Delete a node from the end of LL. ( as a METHOD ) 4. Delete a node...
plz use doubly linked list. java Q1) Create a program that do the following: 1. Asks...
plz use doubly linked list. java Q1) Create a program that do the following: 1. Asks the user to enter n marks for n students, read the marks and the names and store them in a double linked list. 2. Write a method to find the largest mark and print the name of the student having that mark 3. Write a method to print the content of the list (name, mark) 4. Write a method to search the list for...
Exercise 2: Write a program in Java to manipulate a Double Linked List: 1. Create Double...
Exercise 2: Write a program in Java to manipulate a Double Linked List: 1. Create Double Linked List 2. Display the list 3. Count the number of nodes 4. Insert a new node at the beginning of a Double Linked List. 5. Insert a new node at the end of a DoubleLinked List 6. Insert a new node after the value 5 of Double Linked List 7. Delete the node with value 6. 8. Search an existing element in a...
Exercise 1: Write a program in Java to manipulate a Singly Linked List: 1. Create Singly...
Exercise 1: Write a program in Java to manipulate a Singly Linked List: 1. Create Singly Linked List 2. Display the list 3. Count the number of nodes 4. Insert a new node at the beginning of a Singly Linked List. 5. Insert a new node at the end of a Singly Linked List 6. Insert a new node after the value 5 of Singly Linked List 7. Delete the node with value 6. 8. Search an existing element in...
Create a generic Linked List that does NOT use the Java library linked list. Make sure...
Create a generic Linked List that does NOT use the Java library linked list. Make sure it contains or access a subclass named Node (also Generic). And has the methods: addFirst(), addLast(), add(), removeFirst(), removeLast() and getHead(). In a separate Java class provide a main that creates an instance of your LinkedList class that creates an instance of your LinkedList that contains String types. Add the five names (you pick them) to the list and then iterate through the list...
(Java) Create a new linked list from two given arrays with the greater element from each...
(Java) Create a new linked list from two given arrays with the greater element from each corresponding array element placed into the linked list. Given two arrays of varying size initialized with integers of varying values, the task is to create a new linked list using those arrays. The condition is that the greater element value from each corresponding array element will be added to the new linked list in the list position that maintains the integers in ascending order....
Java program to implement circular linked list. NO COPY PASTE ANSWERS plz follow the given template......
Java program to implement circular linked list. NO COPY PASTE ANSWERS plz follow the given template... public class CircularLinkedList { private Node tail; private int size; public CircularLinkedList() { tail= null; size = 0; } public int size(){ return size; } public boolean isEmpty() { return size==0; } //if list is not empty return the first element public E first() { if (isEmpty()) return null; //code here return 0; } //if list not empty return last element public E last()...
Create the following java program with class list that outputs: //output List Empty List Empty List...
Create the following java program with class list that outputs: //output List Empty List Empty List Empty Item not found Item not found Item not found Original list Do or do not. There is no try. Sorted Original List Do There do is no not. or try. Front is Do Rear is try. Count is 8 Is There present? true Is Dog present? false List with junk junk Do or moremorejunk do not. There is no try. morejunk Count is...
Write a Java program to implement a Single Linked List that will take inputs from a...
Write a Java program to implement a Single Linked List that will take inputs from a user as Student Names. First, add Brian and Larry to the newly created linked list and print the output Add "Kathy" to index 1 of the linked list and print output Now add "Chris" to the start of the list and "Briana" to the end of the list using built-in Java functions. Print the output of the linked list.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT