Hi everyone,
here is my problem.

I have a sorted array of dates that is stored in a circular buffer. I have a pointer to last date in buffer. There is a possibility that some dates are missing. Client requires a range of dates. If low limit date is missing, program should return first closest date that is higher then required one and vice versa for upper limit date.
Here is an example:

Dates in circular buffer (int[18]):
1,2,3,4,5,11,12,13,14,15,21,22,23,24,25,26,27,28
and if client wants from 8 to 23,
program should return 11,12,13,14,15,21,22,23.

I tried like this :
(if I detect that I will just go x steps forward and x steps backward I split x in half)

buffer | diff | pointer

1,2,3,4,5,11,12,13,14,15,21,22,23,24,25,26,27,28 -20 (28)
*
1,2,3,4,5,11,12,13,14,15,21,22,23,24,25,26,27,28 +7 (1)
*
1,2,3,4,5,11,12,13,14,15,21,22,23,24,25,26,27,28 -5 (13)
*
1,2,3,4,5,11,12,13,14,15,21,22,23,24,25,26,27,28 +5 -> (5/2)+1=+3 (3)
*
1,2,3,4,5,11,12,13,14,15,21,22,23,24,25,26,27,28 -3 -> (-3/2)-1=-2 (11)
*
1,2,3,4,5,11,12,13,14,15,21,22,23,24,25,26,27,28 +4 (4)
*
1,2,3,4,5,11,12,13,14,15,21,22,23,24,25,26,27,28 -5 (13)
*

If we continue like this we will get 3,11,4,13 over and over again.

Note:
It is only coincidence that we get 11 here. When I use some real examples, with more dates,
this algorithm jumps over some other 4 (or 3) numbers.

Please help.