
This is Java
Linked List Basics ( insertFront, insertBack, deleteFront & deleteBack)
Question: Given the following code in main and output, please write the Java program which allows main to work:
public static void main(String[] args) {
LinkedList list = new LinkedList();
// Try to delete from an empty list
list.deleteFront();
list.displayLL();
list.deleteBack();
list.displayLL();
// insert 3 nodes
list.insert(18);
list.insert(45);
list.insert(12);
list.displayLL();
// Here are the main “new” lines, not included in code I gave you
list.insertFront(1);
list.displayLL();
list.insertBack(999);
list.displayLL();
list.deleteFront();
list.displayLL();
list.deleteBack();
list.displayLL();
} // end of main
This is Java programming please

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images

- PROBLEM STATEMENT: In this problem you will need to insert 5 at the frontof the provided ArrayList and return the list. import java.util.ArrayList;public class InsertElementArrayList{public static ArrayList<Integer> solution(ArrayList<Integer> list){// ↓↓↓↓ your code goes here ↓↓↓↓return new ArrayList<>(); Can you help me with this question The Language is Javaarrow_forwardGiven the interface of the Linked-List struct Node{ int data; Node* next = nullptr; }; class LinkedList{ private: Node* head; Node* tail; public: display_at(int pos) const; ... }; Write a definition for a method display_at. The method takes as a parameter integer that indicates the node's position which data you need to display. Example: list: 5 -> 8 -> 3 -> 10 display_at(1); // will display 5 display_at(4); // will display 10 void LinkedList::display_at(int pos) const{ // your code will go here }arrow_forwardThis is using Data Structures in Javaarrow_forward
- Given the following class declaration: class List { public: List(); List(const List&); List& operator=(const List&); -List(); // Inserts element in the specified position, returns true if // it was able to insert. // Example, if the list is [4, 2, 1], and the user // calls list.Insert(6, 1) the list would become [4, 6, 2, 1] bool Insert(double element, size_t position) ; // Returns the position of element if found, if not found returns -1 int Index0f(double element)const ; // Removes the element in the given position double Remove(size_t position) ; // Gets the number in the given position double Get(size_t position)const ; // Returns a string representation of the list, elements // separated by commas and the list between brackets string ToString()const ; // Returns the number of elements in the list size_t Size)const; // Returns true if the list is empty, false otherwise bool IsEmpty)const; // Clears the whole list void Clear(); private: struct Node{ double number; Node* next; };…arrow_forwardIN JAVA PLEASE, need help finding an element in the list /** * Returns whether the given value exists in the list. * @param value - value to be searched. * @return true if specified value is present in the list, false otherwise. */ public int indexOf(int value) { //Implement this method return -1; }arrow_forwardStarter code for ShoppingList.java import java.util.*;import java.util.LinkedList; public class ShoppingList{ public static void main(String[] args) { Scanner scnr=new Scanner(System.in); LinkedList<ListItem>shoppingList=new LinkedList<ListItem>();//declare LinkedList String item; int i=0,n=0;//declare variables item=scnr.nextLine();//get input from user while(item.equals("-1")!=true)//get inputuntil user not enter -1 { shoppingList.add(new ListItem(item));//add into shoppingList LinkedList n++;//increment n item=scnr.nextLine();//get item from user } for(i=0;i<n;i++) { shoppingList.get(i).printNodeData();//call printNodeData()for each object } }} class ListItem{ String item; //constructor ListItem(String item) { this.item=item; } void printNodeData() { System.out.println(item); }}arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





