mình làm theo ý tưởng mã đi tuần nhưng mà nó chạy ra sai, bạn nào xem giúp mình với

Code:
#include<iostream>
#include<iomanip>
#include<fstream>

using namespace std;



int dong[] = {1, -1, 0, 0};
int	cot[]=   {0, 0, 1, -1};
#define MAX 10


class Graph
{
protected:
	int m_iN; //so dong cua ma tran
	int m_iM; // so cot cua ma tran
	
	int arrA[MAX][MAX];
	int DanhDau[MAX];
	
	int m_iNuocDi;
	
	struct 
	{
		int m_iX;
		int m_iY;
	}ViTri[2];

	struct
	{
		int x;
		int y;
	} DuongDi[MAX];

	

public:
	void GetData();
	void KhoiTao();
	bool KiemTra(int xNew, int yNew, int n);
	void InDuongDi();
	void TimDuongDi(int n, int x, int y);
};



void Graph::GetData()
{
	ifstream fin;
	fin.open("inRobot.txt");
	if(fin.is_open())
	{
		while(!fin.eof())
		{
			fin >> ViTri[0].m_iX >> ViTri[0].m_iY >> ViTri[1].m_iX >> ViTri[1].m_iY;
	
			fin >> m_iN >> m_iM;

			for(int i = 0; i < m_iN; i++)
				for(int j = 0; j < m_iM; j++)
					fin >> arrA[i][j];
		}
	}

}


void Graph::KhoiTao()
{
	for(int i = 0; i < MAX; i++)
		DanhDau[i] = 0;
}

void Graph::InDuongDi()
{
	for(int i = 0; i < m_iNuocDi; i++)
		cout << DuongDi[i].x << " " << DuongDi[i].y << endl;


}


bool Graph::KiemTra(int xNew, int yNew, int n)
{
	if(xNew >= 0 && xNew < m_iM && yNew >= 0 && yNew < m_iN && arrA[xNew][yNew] != 0 && DanhDau[n] == 0)
		return true;

	return false;
}

void Graph::TimDuongDi(int n, int x, int y)
{
	int i ;
	DanhDau[n] = 1;
	for(i = 0; i < 4; i++)
	{
		int yNew = y + dong[i];
		int xNew = x + cot[i];

		if(KiemTra(xNew, yNew, n + 1))
		{
			DuongDi[n].x = xNew;
			DuongDi[n].y = yNew;

			if((xNew == ViTri[1].m_iX) && (yNew == ViTri[1].m_iY))
			{
				m_iNuocDi = n;
				InDuongDi();
				exit(1);
			}
			else
			{
				TimDuongDi(n + 1, xNew, yNew);
			}

			DuongDi[n].x = 0;
			DuongDi[n].y = 0;
		}
	}
}

void main()
{
	Graph g;
	g.GetData();
	g.KhoiTao();
	int x = 0; int y = 0;
	g.TimDuongDi(1, x, y);

}