binary-search

Anonymous
c_cpp
08/18/2024 5:09 AM
424 B
18
Indexable
int Search(int a[], int start, int last, int item)
{
  int mid;
  if(last >= start)
  {
    mid = (start + last)/2;
    if(a[mid] == item){
       return mid+1;
    }
    else if(a[mid] < item){
       return Search(a,start,mid+1,item);
    }
    else{
       return Search(a,mid-1,last,item);
    }
  }
  return -1;
}
Editor is loading...
Leave a Comment