About this algorithm
It works when the array is empty (b.length = 0) --return -1.
If x is in b, finds its rightmost occurrence
If x is not in b, finds position where it belongs
In general, it�s faster than a binary search that stops as soon as x is found. The latter kind of binary search needs an extra test (x = b[k]) in the loop body, which makes each iteration slower; however, stopping as soon as x is found can be shown to save only one iteration (on the average).
It�s easy to verify correctness of the algorithm --to see that it works.