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

📄 maze.cpp

📁 数据结构迷宫
💻 CPP
字号:
#include <iostream.h>
#include <iomanip.h>

int Maze[11][10]={  {1,1,1,1,1,1,1,1,1,1},
					{1,0,0,1,0,0,0,1,0,1},
					{1,0,0,1,0,0,0,1,0,1},
					{1,0,0,0,0,1,1,0,1,1},
					{1,0,1,1,1,0,0,1,0,1},
					{1,0,0,0,1,0,0,0,0,1},
					{1,0,1,1,1,1,0,0,1,1},
					{1,0,1,1,1,1,0,0,1,1},
					{1,1,1,0,0,0,0,0,1,1},
					{1,1,1,0,0,0,0,0,0,1},
					{1,1,1,1,1,1,1,1,1,1} };

//位置点数据结构

struct point
{
	int x;		    //point对应的x坐标
	int y;			//point对应的y坐标
	int direction;  //
	int type;       //
	point *pre;
};

//迷宫通道堆栈
class passage
{
public:
	passage();
	bool Push( point * );
	bool Pop();
private:
	point *base;
	point *top;
};
passage::passage()
{
	base = new point;
	top  = base;
}
bool passage::Push(point * e)
{
	e->pre = top->pre ;
	top->pre = e;
	return true;
}
bool passage::Pop()
{
	if( top == base )
	{
		cout<<"该堆栈为空。"<<endl;
		return false;
	}
	top = top->pre;
	return true;
}

//构造迷宫
void intputMaze()
{
	cout<<"****测试迷宫阵****"<<endl; 
	cout<<" 0 通道,1 障碍物 "<<endl;
	cout<<"(起始点(1,1),终点(8,9))"<<endl;
	cout<<"------------------------"<<endl;
	for(int i=1; i<10; i++)
	{
		for(int j=1; j<9; j++)
		{
			cout<<setw(3)<<Maze[i][j];
		}
		cout<<endl;
	}
	cout<<"--------------------------"<<endl;
}

//走迷宫
bool FindPath()
{
	int x=1;
	int y=1;
	passage test;
	point newtest;
	newtest.x = x;
	newtest.y = y;
	newtest.direction = 1;
	test.Push( &newtest );
	for(;;)
	{
			
	}
	return true;
}

//测试
void main()
{
	cout<<"**************迷宫测试**************"<<endl;
	cout<<endl;
	intputMaze();
	if( FindPath() )
		cout<<"走出迷宫"<<endl;
	else
		cout<<"该迷宫无出口"<<endl;
	cout<<"测试完毕,敬请指教"<<endl;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -