⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 maze.h

📁 包含各种测试,查找和算法等代码,如冒泡算法,树的遍历,链表,队列,堆栈等
💻 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 + -