I see a lot of templates and complicated data structures for implementing a circular buffer.
How do I code a simple integer circular buffer for 5 numbers?
I\
Take an array, arr, an index idx, and a counter, num.
arr
idx
num
To insert foo, say arr[idx++] = foo; idx %= buffer_len; num++;.
foo
arr[idx++] = foo; idx %= buffer_len; num++;
To read out an item into foo, say foo = arr[(idx-num)%buffer_len]; num--;.
foo = arr[(idx-num)%buffer_len]; num--;
Add boundary checks.