Question: java the linked list code is import java.util.NoSuchElementException; import java.util.Iterator; public interface ReadonlyList { T get(int index); int size(); Iterator iterator(); } public class LinkedList
java
the linked list code is
import java.util.NoSuchElementException;
import java.util.Iterator; public interface ReadonlyList{ T get(int index); int size(); Iterator iterator(); }
public class LinkedListimplements ReadonlyList { private ListNode header = new ListNode (); public boolean isEmpty() { return header.getNext() == null; } public T getFirst() { ListNode first = header.getNext(); if (first == null) { throw new NoSuchElementException("List is empty, no item to get!"); } else { return first.getValue(); } } public void addFirst(T value) { // Create a new node ListNode newNode = new ListNode (); // Store the new value in the new node newNode.setValue(value); // Link the new node to the old first node newNode.setNext(header.getNext()); // Set the new node as the first node header.setNext(newNode); } public void removeFirst() { ListNode first = header.getNext(); if (first == null) { throw new NoSuchElementException("List is empty, no item to remove!"); } else { header.setNext(first.getNext()); } } public T get(int index) { int k = 0; ListNode current = header.getNext(); while (k current = header.getNext(); while (current != null) { k++; current = current.getNext(); } return k; } public String toString() { ListNode current = header.getNext(); if (current == null) { return "[]"; } else { StringBuilder stringBuilder = new StringBuilder("["); stringBuilder.append(current.getValue()); while(current.getNext() != null) { stringBuilder.append(", "); current = current.getNext(); stringBuilder.append(current.getValue()); } stringBuilder.append("]"); return stringBuilder.toString(); } } public LinkedListIterator iterator() { return new LinkedListIterator (header); } }

2. [20 points] Write an implementation of bubble sort as an instance method called sort for the LinkedList class developed in lecture. sort ) should take a Comparator
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
