#include<iostream>
using namespace std;
struct treeNode{
int indexI,indexJ;
treeNode *Right,*Down;
};
treeNode*Try(int i,int j,int n,int x=0);
void preorderPrint( treeNode *root );
int**Array;
void read(int**A,int n){
for(int i=0;i<n;i++)>
for(int j=0;j<n;j++){>
cout<<"\nEnter the element["<<i<<"]["<<j<<"]: ";
cin>>A[i][j];
}
}
void main(){
int size;
cout<<"\nEnter the size of the array : ";
cin>>size;
Array=new int*[size];
for(int i=0;i<size;i++)>
Array[i]=new int[size];
read(Array,size);
treeNode*root=Try(0,0,size);
preorderPrint( root );
}
treeNode*Try(int i,int j,int n,int x){
treeNode*p=new treeNode;
if(Array[i][j]!=-1){
bool b=false;
if(x==0){
if((Array[i][j]+j)<n){>
p->indexI=i; p->indexJ=j;
b=true;}
}
else{
if((Array[i][j]+i)<n){>
p->indexI=i; p->indexJ=j;
b=true;}
}
if(b){
p->Right=Try(i,j+Array[i][j],n,0);
p->Down=Try(i+Array[i][j],j,n,x=1);
return p;
}
else
return NULL;
}
}
void preorderPrint( treeNode *root ) {
if ( root != NULL ) { cout << root->indexI << " "<<root->Right<<" "; preorderPrint( root->Down ); preorderPrint( root->Right ); }
}
The program is throwing exceptions and I do not know why.