Question: JAVA Reference: https://docs.oracle.com/javase/8/docs/api/java/util/AbstractList.html You are going to implement a doubly linked list class called SimpleList. This class extends the Java Collections Framework class AbstractList which
JAVA
Reference: https://docs.oracle.com/javase/8/docs/api/java/util/AbstractList.html You are going to implement a doubly linked list class called SimpleList. This class extends the Java Collections Framework class AbstractList which you can read about in the above API reference1. We walked through most of the code for singly linked lists in class, so just extend that a little bit to handle the idea of doubly linked lists.
Plz with the JAVADOC
import java.util.AbstractList; import java.util.NoSuchElementException; import java.util.Iterator;
//Simple linked list class based on AbstractList //READ THE DOCUMENTATION for AbstractList for more information //on how these methods should work and when exceptions should //be thrown. This data structure does not allow adding null //elements. class SimpleList extends AbstractList { //Add more instance variables here... //private or protected only! //Constructor public SimpleList() { //O(1) } //returns the size public int size(){ //O(1) return -1; } //returns the value at a given index public T get(int index) { //O(n) return null; } //sets the value at a given index and returns //the old value public T set(int index, T value) { //O(n) return null; } //adds a value at a given index public void add(int index, T value) { //O(n) } //appends a value public boolean add(T value) { //O(1) return false; } //removes the value at a given index and returns //the value removed public T remove(int index) { //O(n) return null; } //------------------------------------------------------------- // Main Method For Your Testing -- Edit all you want //------------------------------------------------------------- public static void main(String[] args){ SimpleList letters = new SimpleList<>(); for (int i=0; i<5; i++) letters.add((char)(97+i*2)); if (letters.size() == 5 && letters.get(0) == 'a'){ System.out.println("Yay 1"); } if (letters.set(1,'b') == 'c' && letters.get(1) == 'b'){ System.out.println("Yay 2"); } letters.add(2,'c'); if (letters.size() == 6 && letters.get(2) == 'c' && letters.get(3)=='e'){ System.out.println("Yay 3"); } if (letters.remove(3)=='e' && letters.size() == 5 && letters.get(3)=='g'){ System.out.println("Yay 4"); } } //------------------------------------------------------------- // DO NOT EDIT ANYTHING BELOW THIS LINE EXCEPT TO ADD JAVADOCS //------------------------------------------------------------- //bad practice to have public inst. variables, but we want to test this... public DoubleNode head = null; //provided doubly-linked list node class //bad practice to have public inst. variables, //in a public nested class, but we want to test this... public static class DoubleNode { public T value; public DoubleNode next; public DoubleNode prev; public DoubleNode() { } public DoubleNode(T value) { this.value = value; } } //provided toString() method public String toString(){ StringBuilder sBuilder = new StringBuilder(""); for (T value : this){ sBuilder.append(value); sBuilder.append(" "); } return sBuilder.toString(); } //provided iterator, if your code is working, this should //work too... public Iterator iterator() { return new Iterator() { DoubleNode current = head; public T next() { if(!hasNext()) throw new NoSuchElementException(); T val = current.value; current = current.next; return val; } public boolean hasNext() { return (current != null); } }; } }