Queue using array

in the given program why do we use
this.front=(this.front+1)%this.data.length;
instead of this.front as this.front+1 only.
program:
public int dequeue(int value) throws Exception{
if(this.size()==0){
throw new Exception(“queue is empty”);
}
int rv=this.data[this.front];
this.data[this.front]=0;
this.front=(this.front+1)%this.data.length;
this.rear–;
return rv;
}

pls share the whole code ide link

% is used because we dont know the no of elements initially, we have to consider the elements until sum>=0

so when arr is filled upto its size then again it will start with first cell
e.g
suppose the arr size is 5 and it is filled completely then next element will filled in first cell
(5+1)%5(arr size)=> 1 first cell

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.