Probably tons of mistakes, sorry. I'm new to java and I'm having a rather hard time with all the syntax and whatnot. I can't get past this error but I fail to see where it is. I can't even compile because I get the message: "...uses unchecked or unsafe operations. Note: Recompile with -Xlint: unchecked for details" Help, please.
This is supposed to implement the Queue interface which is pretty much just
public boolean enqueue(Item item);
public Item dequeue();
public int size;
public boolean isEmpty();
public boolean isFull();
I did try to make it circular but I don't know if I've succeeded. I think it's those generics that bring about the problem, i don't know.
public class ArrayQueue<Item> implements Queue<Item> {
private Item[] q;
public int N = 0;
private int tail = 0;
private int head = 0;
public ArrayQueue(int capacity) {
q = (Item[]) new Object [capacity];
}
public boolean enqueue(Item item) {
if (isFull())
return false;
q[tail++] = item;
if(tail == q.length )
tail = 0;
N++;
return true;
}
public Item dequeue( ) {
if (isEmpty( ) )
return null;
N--;
Item headItem = q[head];
q[head++] = null;
if(head == q.length )
head = 0;
return headItem;
}
public int size( ) {
return N;
}
public boolean isFull() {
return N == q.length;
}
public boolean isEmpty() {
return N == 0;
}
}