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 func

来源:学生作业帮助网 编辑:作业帮 时间:2024/10/06 10:54:50
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 func
xS=o@+C8ľ+"@pTb7&+mvݵ %W!!T4?s6/XsJ;;͛78vhu:2_zz`.0.TDSNSPHd%% 5J &j 2QIu!9@uTatfq;gD#tk޳%;#ȨT47F%\iZs H}%KʳXFnfClkp06d,J XyO I%a*œW`y:q3\mv|&RHIEz Guz{-8.M|?U5ۭ_z߆^߫7}.k992/l4M'I{ٸNrx\ 78Ϛ${ VJđ X

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 func
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;
}

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 func
二分搜索啦!
//假定升序排列
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