int Find(int* arr, int nLength, int nElement)
{
int nBegin = 0, nEnd = nLength - 1, nIndex;
while (nBegin <= nEnd)
{
nIndex = (nBegin + nEnd) / 2;//(nBegin+nEnd)>>1 //或者位移,但是更高效
if (nElement > arr[nIndex])
{
nBegin = nIndex + 1;
}
else if (nElement < arr[nIndex])
{
nEnd = nIndex - 1;
}
else
{
return nIndex;
}
}