I'm filling out this table and wondering if I did it right:
We learned it like this: dequeue(Q) -> returns most front (right-hand) element enqueue(Q,k) -> inserts k as new most rear (left-hand) element
I'm kinda unsure because I have to make a shift, when I want to enqueue a new item (all other items shift by one to the front), is that correct?
Thanks for your help!
This diagram is correct for one implementation of the queue data structure.
If the row of boxes represents a fixed size array, it's not a very efficient implementation because of the shifting as you've observed. A different implementation called circular queue removes the need to shift items.