Im having trouble seeing this recursion function through. Say I have an 8 by 8 array how would I get the search function to "see" into the middle of the 8 by 8 array. Positions (4,4), (4,5),(5,4),(5,5).
#include <iostream>
using namespace std;
struct matrix
{
int size;
int row;
int col;
int newsize;
};
class tri
{
public:
int expvalue(int);
void origin(int**,int, int, int);
void search(int**, int);
private:
matrix **listPtr;
};
int tri::expvalue(int n)
{
if(n==0)
return 1;
else
return 2*expvalue(n-1);
}
void tri::origin(int** ptr, int n, int a, int b)
{
ptr=new int*[n];
cout<<"Origin Matrix: \n"<<endl;
for(int i = 0; i <n; i++)
{
ptr[i] = new int[n];
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
ptr[i][j]=1;//whats in the matrix
ptr[a-1][b-1]=0;//missing square
cout << ptr[i][j] << ' ';//display matrix
}
cout<<endl;
}
}
void tri::search(int**ptr, int a)
{
if()
return false;
else
{
int midpoint;
midpoint=(a)/2;
if()
return search();
else if()
return true;
else
return search();
}
}
void main()
{
matrix num;
tri print;
int **listPtr=NULL;
cout<<"Enter matrix size: ";
cin>>num.size;
cout<<"Enter row number: ";
cin>>num.row;
cout<<"Enter column number: ";
cin>>num.col;
num.newsize=print.expvalue(num.size);
print.origin(listPtr, num.newsize, num.row, num.col);
cout<<num.newsize;
}