i’m not really into basics algorithm programming, so here’s my problem. I want to create an algorithm which can populate a circular buffer but it have to start at the end of the buffer. I am trying to do it since many hours without succes, so i ask for your help.
I know the original algorithm which start by the begining of the buffer :
i = (i+1)%buffLen
But i want something that put something from buffLen-1 to 0, and when it reach 0, it start over from buffLen-1.
I know it can be done with a condition, but i’m sure there is a formula to do it faster and cleaner.
I need it to iterate infinitly through an array of objects by the end.
Sorry for my bad english.
Try
It isn’t going to be any more efficient than (or even as efficient as) an
if..elseconstruct, but it’s the analog to the one-line assignment for moving in the positive direction.