I found the following question, and couldn't get the best answer:
if you have a sorted and shifted array such like {5,6,7,1,2,3,4}, how
to find one element "2"?
If you meant that every unshifted sequence, you want to search through
has
in general the form {1,2,3,4,...,n}|n = amount of elements
You could easily calculate about how many elements it is shifted,
through:
shiftingRange = n - (firstValue - 1)
this algorithm would return 7 if firstValue is 1, which is the same
sequence
because it`s a full shift, but 0 would be nicer, to get this you could
do this:
shiftingRange = (n - (firstValue - 1))%n
So you would get the index of the value you are searching for with
find(x) = (shiftingRange + x - 1) % 7 // -1 to make it a c++ array
index, which starts by zero
find(2) = ((7 - (5 - 1))%7 + 2 - 1) % 7 = 4 // with your sequence as
example
find(5) = (3 + 5 - 1) % 7 = 0
My answer is just a guess of what you could have meant,
you should represent what do you want to achieve.