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

Data structure Take your time. No rush. Promise to give u thumbs up. Please give

ID: 3873273 • Letter: D

Question

Data structure

Take your time. No rush.

Promise to give u thumbs up.

Please give me the correct answer.

here   ,,, list.java is,,,,below

*********   and circular linked list.java    is,,,,,,,,,,,,,,,

Thank you.

Please give me the correct answer,, and i will give u more in the future,,,  

thanks,,  

Page 1 of 6 Circular Linked List Assignment Overview A circular linked list is essentially a singly linked list in which the next pointer of the tail node is set to point to the head node of the linked list rather than set to nul. The first figure below shows a linked list as a singly linked list. The second figure below shows the singly linked list from the first figure as a circular linked list. In this assignment, you will write code for an implementation of a circular linked list 12 Head Tail Singly Linked List 12 Tail Circular Linked List

Explanation / Answer

import java.util.Iterator;
import java.util.ConcurrentModificationException;
import java.util.NoSuchElementException;

public class CircularLinkedList<AnyType> implements List<AnyType>
{
private static class Node<AnyType>
{
private AnyType data;
private Node<AnyType> next;

public Node(AnyType d, Node<AnyType> n)
{
setData(d);
setNext(n);
}

public AnyType getData() { return data; }

public void setData(AnyType d) { data = d; }

public Node<AnyType> getNext() { return next; }

public void setNext(Node<AnyType> n) { next = n; }
}

private int theSize;
private int modCount;
private Node<AnyType> tail;

public CircularLinkedList()
{

}

public void clear()
{
(List)this.clear();
}

public int size()
{
return (List)this.size();
}

public boolean isEmpty()
{
if((list)this.isEmpty())
return true;
else
return false;
}

public AnyType get(int index)
{
return (List)this.get(index).getData();
}

public AnyType set(int index, AnyType newValue)
{
AnyType tempData = (List)this.get(index).getData();
(List)this.get(index).setData();
return tempData;
}

public boolean add(AnyType newValue)
{
add(size(), newValue);
return true;
}

public void add(int index, AnyType newValue)
{
List tempList = (List)this;
Node current = temp.get(index-1);
Node sNode = new Node(newValue, current.getNext());
current.setNext(sNode);
int pos = tempList.size()-1;
list.add(tempList.get(pos));
while(pos!=index){
tempList.set(pos,tempList.get(pos-1));
}
}

public AnyType remove(int index)
{
List tempList = (List)this;
Node current = temp.get(index);
tempList.remove(index);
return current;
}

public void rotate()
{
List tempList = (List)this;
Node tempFirst = tempList.get(0);
Node tempLast = tempList.get(tempList.size()-1);
tempFirst.setNext(tempLast);
tempFirst.setData(tempLast.getData());
tempLast.setNext(tempList.get(0).getNext);
tempLast.setData(tempList.get(0).getData());
tempList.set(0,tempLast);
tempList.set(tempList.size()-1,tempFirst);
tail = tempFirst;
}

public Iterator<AnyType> iterator()
{
return new LinkedListIterator();   
}

private Node<AnyType> getNode(int index)
{
return (getNode(index, 0, size()-1));
}

private Node<AnyType> getNode(int index, int lower, int upper)
{
return (List)this.get(index);
}

private class LinkedListIterator implements Iterator<AnyType>
{
private Node<AnyType> previous;
private Node<AnyType> current;
private int expectedModCount;
private boolean okToRemove;

LinkedListIterator()
{
current = tail.getnext();
}

public boolean hasNext()
{
if(current.getnext()==null)
return false;
else
return true;
}

public AnyType next()
{
return current.next();
}

public void remove()
{
current = null;
}
}
}