ArrayBinarySearch
使用IComparable<T>接口,搜索升序一维数组指定值来比较元素。
template<typename T>
int ArrayBinarySearch(
T& array[], // 用于搜索的数组
const int start_index, // 索引起始点
const int count, // 搜索范围
T value, // 搜索值
IComparer<T>* comparer // 比较接口
);参数
&array[]
[out] 要搜索的数组。
value
[in] 已搜索的值。
*comparer
[in] 接口用于比较元素。
start_index
[in] 搜索开始的索引起始点。
count
[in] 搜索范围长度。
返回值
返回找到元素的索引。如果搜索值未找到,它将返回最接近值的最小元素的索引。