c++ 这题什么意思?怎么写?

问题描述:

c++ 这题什么意思?怎么写?
// Recursive binary search via pointers. If the target is found, return a pointer to it. // Otherwise return NULL.template
int * binarySearch(T * firstPtr, T * lastPtr, const T &target);// Top-level binary search function. Calls the function above.
// Return index of target in values or -1, if target isn't found.template int binarySearch(T values[], int size, const T &target) { int * loc = binarySearch(values, values+size-1, target); return loc == NULL ? -1 : loc-values;
}
1个回答 分类:综合 2014-09-23

问题解答:

我来补答
二分搜索啦!
//假定升序排列
template
int *binarySearch(T* fistPtr,T* lastPtr,const T& target)
{
T *middle=(fistPtr+lastPtrt)>>1;
if (*middle==target)
{
return middle;
}
if (fistPtr==lastPtr)
return null;
if (*middle
 
 
展开全文阅读
剩余:2000
下一页:请说清为什么