?? maze.h
字號:
struct InterSection
{
int left;
int forward;
int right;
};
class Maze
{
private:
int mazeSize;
InterSection *intSec;
int Exit;
public:
Maze(char *filename); //構造函數
~Maze(void); //析構函數
int TravMaze(int intSecValue); //迷宮搜索
};
Maze::Maze(char *filename) //構造函數
{
ifstream fin;
fin.open(filename, ios::in||ios::nocreate);
if(!fin)
{
cerr << "數據文件無法打開!";
exit(0);
}
fin >> mazeSize;
intSec = new InterSection[mazeSize+1];
for(int i = 1; i <= mazeSize; i++)
fin >> intSec[i].left >> intSec[i].forward >> intSec[i].right;
fin >> Exit;
fin.close();
}
Maze::~Maze(void) //析構函數
{
delete []intSec;
}
int Maze::TravMaze(int intSecValue) //迷宮搜索
{
if(intSecValue > 0)
{
if(intSecValue == Exit)
{
cout << intSecValue << " <== ";
return 1;
}
else if(TravMaze(intSec[intSecValue].left))
{
cout << intSecValue << " <== ";
return 1;
}
else if(TravMaze(intSec[intSecValue].forward))
{
cout << intSecValue << " <== ";
return 1;
}
else if(TravMaze(intSec[intSecValue].right))
{
cout << intSecValue << " <== ";
return 1;
}
}
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -