Skip to content

Instantly share code, notes, and snippets.

@ahmedshahriar
Created September 30, 2019 13:48
Show Gist options
  • Save ahmedshahriar/c6082f3a65db71f430eb41c608fe1c02 to your computer and use it in GitHub Desktop.
Save ahmedshahriar/c6082f3a65db71f430eb41c608fe1c02 to your computer and use it in GitHub Desktop.
int searchBinary(int arrayList[],int findNum,int first , int last ){
while(first<=last){
int middle =( last+first)/2;
if(arrayList[middle]==findNum)
return middle;
else if (arrayList[middle]<findNum) //ignore left half
return searchBinary(arrayList,findNum,middle+1,last);
else
return searchBinary(arrayList,findNum,first,middle-1);
}
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment