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

Trying to modify the class LinkedList given by adding to it the functions listed

ID: 3656787 • Letter: T

Question

Trying to modify the class LinkedList given by adding to it the functions listed below. In a. toString(): modify the display function to overload the toString function of the Object class. b. int length(): create this function to determine the number of items in the list (accessor function). c. void clear(): create this function to remove all of the items from the list. After this operation is completed, the length of the list is zero. d. void insertEnd(int item): create this function to insert item at the end of the list. e. void replace(int location, int item): create this function to replace the item in the list at the position specified by location. The item should be replaced with item. f. int get(int location): create a function that returns the element at the position location. public class Main {public static void main(String args[]) {LinkedList intList = new LinkedList(); System.out.print("List of numbers before list creation: "); for (int i =0; i < 10; i++) {int info = (int)(Math.random()*10); System.out.print(info + " "); intList.insert(info); }System.out.print(" List of numbers after list creation: "); intList.display(); System.out.print(intList); //PRINTING THE OBJECT AS A STRING } } public class LinkedList { private Node first; public LinkedList() { first = new Node(); } public String toString() { return "first node info " + first.getNext().getInfo()+ "" + "first node address" + first.getNext(); } public boolean isEmpty() { return (first.getNext() == null); } public void display() { Node current = first.getNext(); while (current != null) { System.out.print(current.getInfo() + " "); current = current.getNext(); } System.out.println(); } public boolean search(int x) { Node current = first.getNext(); while(current != null) { if (current.getInfo() == x) return true; current = current.getNext(); } return false; } public void insert(int x) { Node p = new Node(); p.setInfo(x); p.setNext(first.getNext()); first.setNext(p); } public void remove(int x) { Node old = first.getNext(), p = first; //Finding the reference to the node before the one to be deleted boolean found = false; while (old != null && !found) { if (old.getInfo() == x) found = true; else { p = old; old = p.getNext(); } } //if x is in the list, remove it. if (found) p.setNext(old.getNext()); } } public class Node { private int info; private Node next; public Node() { info = 0; next = null; } public void setInfo(int i) { info = i; } public void setNext(Node L) { next = L; } public int getInfo() { return info; } public Node getNext() { return next; } }

Explanation / Answer

please post the code in a readable way ill help you

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