the code below is my code for binary search using recursion after I wrote it and just googled the code if I had written correctly or not but I found on websites a different code using mid value passing first and last value of array in binary search function so is my code any wrong or the website are making things complicated ?
#include <bits/stdc++.h>
using namespace std;
int binarysearch(int a[],int n,int no)
{
if (n>=1)
{
if(a[n/2]==no)
{
return (n/2);
}
else if (a[n/2]>no)
{
return binarysearch(a,n/2,no);
}
else if (a[n/2]<no)
{
return binarysearch(&a[n/2]+1,n/2-1,no);
}
}
else
return -1;
}
int main(){
int a[]={10,12,19,22,25};
int n = sizeof(a)/sizeof(int);
int f;
cin>>f;
cout<<(binarysearch(a,n,f));
}