Code doubt in video

why cant we just write this.front++ in the dequeue method instead of this.front = (this.front+1 )%data.length

Hi @himanshuep32, Using front++ will limit your inserting to size of array for example if the size of array is 5 you can only insert 5 elements. So if you insert a element and then pop it then the free space made by removing or popping the element cannot be reused … While in case of this.front=(this.front+1)%data.length you can reuse that space as taking mod with data.length will make array circular … That means if size of array is 5 then after index 4 you will check index 0 again and if that index is free you can insert element at index 0. However with this.front++ you cannot do so. Hope this helps

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.