I'm supposed to implement a queue using a singly linked circular linked list (it also has to be generic). It keeps saying there are incompatible types at lines 44 and 45. I've honestly been trying to work this out for hours, but I don't understand what i'm doing wrong. Any help would greatly be appreciated.
import java.util.NoSuchElementException;
public class Queue<T>
{
private int manyItems; //the number of items in the queue
private ListNode<T> rear;
public Queue()
{
rear=null;
manyItems=0;
}
public T getFront() //used to remove the front item and return the item which was deleted
{
if(manyItems==0)
{
throw new NoSuchElementException("Queue underflow");
}
else
{
T temp;
ListNode<T>q=rear.link;
temp=q.data;
rear.link=rear.link.link;
--manyItems;
return temp;
}
}
public <T> void insert(T item)
{
if(manyItems==0)
{
ListNode <T> rear=new ListNode<T>();
rear.data=item;
rear.link=rear;
++manyItems;
}
else
{
ListNode <T>q=new ListNode<T>();
q.link=rear.link;
rear.link=q;
q.data=item;
rear=rear.link;
++manyItems;
}
}
public boolean isEmpty( )
{
if(manyItems==0)
{
return true;
}
else
{
return false;
}
}
/* private int nextIndex(int i)
// Precondition: 0 <= i and i < data.length
// Postcondition: If i+1 is data.length,
// then the return value is zero; otherwise
// the return value is i+1.
{
if(i<data.length-1)
{
return i+1;
}
else
{
return 0;
}
}
*/
public int size( )
{
return manyItems;
}
}
public class ListNode <T>
{
public T data;
public ListNode<T> link;
}