This is likely the problem causing your heap corruption:
back = (back - 1) % size;
In C++, taking the modulus of a negative number results in a negative number. So you can get the same effect using:
back = (back + size-1) % size;
Also, your displayQueue()
function does not take into account the modulus for i
.