I am trying to implement binarySerach recursively, but I got stack overflow.
First I have find function that takes 3 parameters. Then I call this function in main and pass adresess from the array. Nut I have got stack overflow!
First I have find function that takes 3 parameters. Then I call this function in main and pass adresess from the array. Nut I have got stack overflow!
bool find( const int x, const int* pBegin, const int* pEnd)
{
int medel = (*pBegin +( *pEnd - *pBegin)/2) ;
if( pBegin <= pEnd)
{
if(x == medel)
return true ;
else if( x > medel)
{
int begin = (medel +1);
return find (x, &begin, pEnd);
}
else if( x< medel)
{
int last = (medel-1);
return find(x,pBegin, &last);
}
}
else
return false;
}// find
void main()
{
int arr[10];
for (int i=0;i<10;++i)
arr[i] = i;
bool found= find(7, &arr[0], &arr[10]);
cout << "hittat = " << found<< endl;
system("pause");
}