In the implementation of Cyclic Queue, the tail pointer points to the position 1 past the last element in the queue:
|1|2|3|4|5| | |
^ ^
front tail
why?
I think I can implement the Cyclic Queue with the tail pointer pointing to the very last element, not 1 past the last.
You can, indeed implement it that way. There’s a certain symmetry to having the tail pointer point to the position 1 past the last element:
frontpoints to the first (oldest) used element – the next element to be readtailpoints to the first (oldest) unused element – the next element to be writtenIn either case, you need to do a bit more to distinguish between a full cyclic queue and an empty one. Some of the alternatives (including doing things your way) are discussed in the Wikipedia article on circular buffers.