arrayscomplexityqueues
Track size to distinguish a full ring buffer
Anonymous
A ring buffer can use a head index and a size. The tail index is (head + size) % capacity; after adding or removing an item, adjust size, and advance head after removal. Then size zero means empty and size equal to capacity means full, without leaving an unused slot. Each operation takes O(1) time.
0