Question
public class CircularDoublyLinkedList implements List { private class Node { private E value; private Node next, prev; public Node(E value, Node next, Node prev) {
public class CircularDoublyLinkedList
private class Node {
private E value;
private Node next, prev;
public Node(E value, Node next, Node prev) {
this.value = value;
this.next = next;
this.prev = prev;
}
public Node(E value) {
this(value, null, null); // Delegate to other constructor
}
public Node() {
this(null, null, null); // Delegate to other constructor
}
public E getValue() {
return value;
}
public void setValue(E value) {
this.value = value;
}
public Node getNext() {
return next;
}
public void setNext(Node next) {
this.next = next;
}
public Node getPrev() {
return prev;
}
public void setPrev(Node prev) {
this.prev = prev;
}
public void clear() {
value = null;
next = prev = null;
}
} // End of Node class
private class ListIterator implements Iterator
private Node nextNode;
public ListIterator() {
nextNode = header.getNext();
}
@Override
public boolean hasNext() {
return nextNode != trailer;
}
@Override
public E next() {
if (hasNext()) {
E val = nextNode.getValue();
nextNode = nextNode.getNext();
return val;
}
else
throw new NoSuchElementException();
}
} // End of ListIterator class, DO NOT REMOVE, TEST WILL FAIL
/* private fields */
private Node header, trailer; // "dummy" nodes
private int currentSize;
public CircularDoublyLinkedList() {
/**
* Set dummy nodes to point to each other
*
* --> header trailer
* | |
* __________________________
*
*/
header = new Node();
trailer = new Node(null, header, header);
header.setNext(trailer);
header.setPrev(trailer);
currentSize = 0;
}
@Override
public void add(E obj) {
/*TODO ADD YOUR CODE HERE*/
}
@Override
public void add(E elm, int index) {
/*TODO ADD YOUR CODE HERE*/
}
@Override
public boolean remove(E obj) {
/*TODO ADD YOUR CODE HERE*/
return false;
}
@Override
public boolean remove(int index) {
/*TODO ADD YOUR CODE HERE*/
return false;
}
@Override
public int removeAll(E obj) {
/*TODO ADD YOUR CODE HERE*/
return -1;
}
@Override
public E get(int index) {
/*TODO ADD YOUR CODE HERE*/
return null;
}
@Override
public E set(int index, E newElement) {
/*TODO ADD YOUR CODE HERE*/
return null;
}
@Override
public int firstIndexOf(E obj) {
/*TODO ADD YOUR CODE HERE*/
return -1;
}
@Override
public int lastIndexOf(E obj) {
/*TODO ADD YOUR CODE HERE*/
return -1;
}
@Override
public E first() {
/*TODO ADD YOUR CODE HERE*/
return null;
}
@Override
public E last() {
/*TODO ADD YOUR CODE HERE*/
return null;
}
@Override
public int size() {
/*TODO ADD YOUR CODE HERE*/
return -1;
}
@Override
public boolean isEmpty() {
/*TODO ADD YOUR CODE HERE*/
return false;
}
@Override
public boolean contains(E obj) {
/*TODO ADD YOUR CODE HERE*/
return false;
}
@Override
public void clear() {
/*TODO ADD YOUR CODE HERE*/
}
@Override
public Iterator
return new ListIterator();
} //DO NOT DELETE, TESTS WILL FAIL
}
(Fill all TODO)
3. (20 pts) Head over to CircularDoublyLinkedList. java after finishing exercise 2. The instructions for this exercis are as follows: - A circulardoublylinkedList is a linked list where every node has a next pointer and a previous pointer. What going to differentiate this from a regular DoublyLinkediist is that the header and trailer point to each other, making the references at the end of the List circle back to the beginning of the list. - Given the base code, create an implementation of the circularDoublyLinkedList class (with dummy header and trailer) with the knowledge obtained from lectures and previous lab exercises. - Implementations that do not have ALL member methods implemented will receive at most 50% of the credit obtained upon inspection from the professor and/or TAsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started