I am trying to insert items circularly in a queue.. i have the following code but it doesn'n insert them right. what's the problem?
public boolean insert(int element){
if ( head == -1 && tail == -1 ){
head = 0;
tail = 0;
elements[tail] = element;
return true;
}
else if((tail+1)%capacity == head) {
System.out.println("Full");
return false;
}
else {
tail = (tail+1)%capacity;
elements[tail] = element;
return true;
}
}
mainmethod) please? I doubt that the first element isnullsince you store primitives.insertmethod and initializedheadandtailwith-1. Works fine for me.