Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Java please, These are instance methods which modify the linked list ,* acces

ID: 3603711 • Letter: I

Question

In Java please, These are instance methods which modify the linked list ,* accessed through the instance variable: first * Note that this list keeps track of the number of elements in the instance varible N * It is important that N accurately reflect the length of the list.

* You may not add any fields to the node or list classes.

* You may not add any methods to the node class.

static class Node ; } public Node (double item, Node next) { this. i tem item ; this. next next public double item; public Node next int N; Node first; 1/ reference to the first node in the list //number of nodes in list static boolean showMeSuccess = false; // set to true to also see success notifications for tests // set to false to only see Failure notifications for tests

Explanation / Answer

package com.chegg.test;

import java.util.LinkedList;

public class LinkedListTest

{

static class Node{

private double item;

private Node next;

public Node(double item,Node next){

this.item=item;

this.next=next;

}

}

public static void main(String args[])

{

// Creating object of class linked list

LinkedList<String> linkedList = new LinkedList<String>();

// Adding elements to the linked list

linkedList.add("A");

linkedList.add("B");

linkedList.addLast("C");

linkedList.addFirst("D");

linkedList.add(2, "E");

linkedList.add("F");

linkedList.add("G");

System.out.println("Linked list : " + linkedList);

// Removing elements from the linked list

linkedList.remove("B");

linkedList.remove(3);

linkedList.removeFirst();

linkedList.removeLast();

System.out.println("Linked list after deletion: " + linkedList);

// Finding elements in the linked list

boolean status = linkedList.contains("E");

if(status)

System.out.println("List contains the element 'E' ");

else

System.out.println("List doesn't contain the element 'E'");

// Number of elements in the linked list

int size = linkedList.size();

System.out.println("Size of linked list = " + size);

// Get and set elements from linked list

Object element = linkedList.get(2);

System.out.println("Element returned by get() : " + element);

linkedList.set(2, "Y");

System.out.println("Linked list after change : " + linkedList);

}

  

  

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote