两者中哪一个更适合二分查找的实现?
Which of the two is a better for an implementation of binary search?
在一个分别以low和high为左右边界索引的数组中,有以下两种查找中间元素的方法:
1. int mid = (low+high)/2;
2. int mid = low + ((high - low) / 2);
第一个实现只会导致变量溢出。第二个负责。
在一个分别以low和high为左右边界索引的数组中,有以下两种查找中间元素的方法:
1. int mid = (low+high)/2;
2. int mid = low + ((high - low) / 2);
第一个实现只会导致变量溢出。第二个负责。