Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
#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 ) {
           // Print all the items in the tree to which root points.
           // The item in the root is printed first, followed by the
           // items in the left subtree and then the items in the
           // right subtree.
        if ( root != NULL ) {  // (Otherwise, there's nothing to print.)
			cout << root->indexI << " "<<root->Right<<" ";      // Print the root item.
			preorderPrint( root->Down );    // Print items in left subtree.
           preorderPrint( root->Right );   // Print items in right subtree.
        }
     } // end preorderPrint()
The program is throwing exceptions and I do not know why.
Posted 30-Dec-12 7:15am
Edited 30-Dec-12 7:32am
v3
Comments
Sergey Alexandrovich Kryukov at 30-Dec-12 13:41pm
   
This is not how it should work. Execute it under the debugger, tell us in what line the exception is thrown, exactly.
—SA
Ali++paco# at 30-Dec-12 15:13pm
   
dude please if u can help me .... i'm in a very f***ed up situation ..... i know it seems silly but ... i need help :'(
Sergey Alexandrovich Kryukov at 30-Dec-12 19:32pm
   
Strange reply. I hoped you do what I told you to do in my previous comment, but instead you complain about you situation. We say: "Saying "halva-halva" won't make your mouth sweet". If you need help, you need to help us help you.
—SA
Ali++paco# at 30-Dec-12 14:10pm
   
if(Array[i][j]!=0){
bool b=false;
if(x==0){
in this line the "if(Array[i][j]!=0){"
the message is "Unhandled exception at 0x011F3436 in tajwal.exe: 0xC0000005: Access violation reading location 0xFDFDFE01."
hope i made clear lik that
Mattias Högström at 30-Dec-12 15:52pm
   
Your code is not easy to read.
Days like this I really appreciate F#.
 
You have a buffer overrun or underrun. you pointer arithmetic is wrong.
The sequence FDFD tells me that.
In debug mode, allocated memory is surrounded by markers, guard bytes, magic numbers.
 
From http://en.wikipedia.org/wiki/Magic_number_(programming)
FDFDFDFD Used by Microsoft's C++ debugging heap to mark "no man's land" guard bytes before and after allocated heap memory
 
Either variable i or j is out of bounds.
Hover over them and find out their values when the debugger throws the exception
Then go back in the callstack and find out why they are wrong

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

hi friend if ur program has error dont mind just check the Data Structure concepts again if else i can do the same program in java and if u wish i can send u
java is best to do this work dude if u want the mlm structure contact me...
  Permalink  
Comments
PrafullaVedante at 1-Jan-13 23:58pm
   
he he he he he .... If someone is asking you for a solution...then the code shown by him must be the part of the code ...and not whole project .... right ?? How could it possible to replace whole code of project to java .....just because there is problem in only one part of the code ....... Your solution seems most useless solution on Codeproject ...... Still i restrain myself to downvote your solution........ you made my day by giving me a joke of the day .....he he he he he

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 474
1 Maciej Los 390
2 OriginalGriff 318
3 CHill60 205
4 CPallini 179
0 OriginalGriff 6,152
1 Sergey Alexandrovich Kryukov 5,312
2 Maciej Los 3,279
3 Peter Leow 3,184
4 DamithSL 2,490


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 30 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100