The first pointer increments when you remove items. The last pointer increments when you add items.
The modulus is important to make the Queue circular and reuse the unused space. But in your implementation you should check that you aren't already full before accepting to add items.
Hope this helps.
Some comments have been hidden by the post's author - find out more
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Slightly confused over the need for last=(Last+1)%arr.lergth
Being that (x-1)%x always= x-1, shouldn't last just be=Last+1
Cheers
Where did you see x-1?
There should be no subtraction at all in a Queue.
The first pointer increments when you remove items. The last pointer increments when you add items.
The modulus is important to make the Queue circular and reuse the unused space. But in your implementation you should check that you aren't already full before accepting to add items.
Hope this helps.