The program has been debugged by vc6.0, including a header file maze. h and A main program
Add a code indicating the file format.
# Ifndef MAZE_H
# Define MAZE_H
# Include <iostream. h>
# Include <fstream. h>
# Include <stdlib. h>
Typedef struct
{Int left;
Int forward;
Int right;
} Intersection;
Class Maze
{Private:
Int mazesize;
Int EXIT;
Intersection * intsec;
Public:
Maze (char *);
Int TraverseMaze (int );
};
Maze: Maze (char * filename)
{Ifstream fin;
Int I;
Fin. open (filename, ios: in | ios: nocreate );
If (! Fin)
{Cerr <"the maze dose not exist" <endl;
Exit (-1 );
}
Fin> mazesize;
Intsec = new Intersection [mazesize + 1];
For (I = 1; I <= mazesize; I ++)
Fin> intsec [I]. left> intsec [I]. forward> intsec [I]. right;
Fin> EXIT;
Fin. close ();
}
Int Maze: TraverseMaze (int intsecvalue)
// 0 denote for no availble road exist
{
If (intsecvalue> 0)
{If (intsecvalue = EXIT)
{Cout <intsecvalue <'';
Return 1;
}
// Go to left
Else if (TraverseMaze (intsec [intsecvalue]. left ))
{Cout <intsecvalue <'';
Return 1;
}
Else if (TraverseMaze (intsec [intsecvalue]. forward ))
{Cout <intsecvalue <'';
Return 1;
}
Else if (TraverseMaze (intsec [intsecvalue]. right ))
{Cout <intsecvalue <'';
Return 1;
}
}
Return 0;
}
# Endif
# Include "maze. h"
Void main ()
{Char filename [32];
// String filename;
Cout <"enter the data file name :";
Cin> filename;
Maze M (filename );
If (M. TraverseMaze (1 ))
Cout <endl <"you are free" <endl;
Else cout <endl <"you are trapped" <endl;
}
6
0 2 0
3 5 6
0 0 4
0 0 0
0 0 0
7 0 0
7