I am trying to find the 1D peak through Divide and Conquer technique in this particular question, my program even though it runs, but at the time of giving the final output it says that there has been some problem with the execution, I have got the answer from a different method, but I would like to know where am I at fault here.
#include<iostream>
using namespace std;
int a[8];
class pg1
{
public:
int func(int n)
{
if(a[n] <= a[n+1])
{
func(n++);
}
else if(a[n] <=a [n-1])
{
func(n--);
}
else
{
return n;
}
}
};
int main()
{
pg1 ob;
for(int i=0;i<8;i++)
{
cin >> a[i];
}
int x = ob.func(4);
cout << endl << x;
return 0;
}
Input- 5 6 8 5 4 3 6 4
Errors are- 1D Peak.exe has stopped working. A problem caused the program to stop working correctly.Windows will close the program and notify you aif a solution is available.
End Result- Process Exited with return value 3221225725