Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Linear vs. Binary Search. Parent comment
If min+max is a negative signed int, then the result of right shifting is implementation dependent.
Instead, you could do
int middle = (unsigned)(min + max) >> 1;
There are no comments on this comment yet.
If min+max is a negative signed int, then the result of right shifting is implementation dependent.
Instead, you could do
Still, this relies on the original indices falling in the non-negative range of signed ints.