I am implementing the add(E) method in the cyclic DoublyLinkedList class as well as the Node inner class.
Node should be implemented as a private inner class.
D
Code fixed with minimal change (just the else case in add):
class DoublyLinkedList
{
private Node first;
private int size;
public void add(E value)
{
if(first == null)
{
first = new Node(value, null, null);
first.next = first;
first.prev = first;
}
else
{
first.prev.next = new Node(value, first, first.prev);
first.prev = first.prev.next;
}
size++;
}
private class Node
{
private E data;
private Node next;
private Node prev;
public Node(E data, Node next, Node prev)
{
this.data = data;
this.next = next;
this.prev = prev;
}
}
}