1
I am implementing a priority queue through an array, my method for insertion works normally:
public boolean inserir(int n){
if(estaCheia()) {
return false;
}
if(estaVazia()) {
fila[nItens++] = n;
return true;
} else {
int i;
for(i = nItens-1; i>=0; i--) {
if(n > fila[i]){
fila[i+1] = fila[i];
} else{
break;
}
}
fila[i+1] = n;
nItens++;
return true;
}
}
The only problem is when I recover the first element of the queue, I get a free position in the vector, but when I try to insert an Arrayindexoutofbounds expection, I believe it is because the free space in the vector is the first. What should I do to rearrange the array so that it is possible to insert it after removing the first element from the row?