Home > Back-end >  Binary search... Refer to...
Binary search... Refer to...

Time:12-31

Orderly array, the aim is to find in a an array of array b, there is a more efficient solution? After finding b [0] contrast optimization when?

 int BanarySearchArr (const int * a, int aSize, const int * b, int bSize) 
{
int start=0;
Int the end=aSize bSize + 1;
Int mid=0;
While (start & lt; End)
{
Mid=(start and end)/2;
If (b [0]==a (mids))
{
If (b [bSize - 1)!=] [mid + bSize - 1 a)
{
return -1;
}
Else if (! Memcmp (b, a + mid, bSize * sizeof (int)))
{
Return mid;
}
The else
{
return -1;
}
}
Else if (b [0] {
End=mid;
}
Else if (b [0] & gt; A (mids))
{
Start=mid + 1;
}
}
return -1;
}
  • Related