Note that both cpp and java has the binary-search implementation: in cpp, it has
binary_search from stl, and
stdlib; in Java, we have
Arrays.binary_search. But it seems that none of them returns the best-approximate (inserting location) when there is no such element.
So I have to implement my own.. (I somohow remember seeing function of similiar functionality before…)