📄 复件 maze.cpp
字号:
#include <iostream.h>
//位置点数据结构
struct point
{
int x; //point对应的x坐标
int y; //point对应的y坐标
int ordinal; //point 在路径的序号
int direction; //走向下个位置的方向
int styl; //地点类型
};
//迷宫通道堆栈
class passage
{
public:
passage(int);
void InitStack();
point * GetTop();
passage & Push( point e);
passage & Pop();
private:
int *base;
int *top;
int stacksize;
};
passage::passage(int size )
{
stacksize = size;
}
void passage::InitStack()
{
base = new point;
top = base;
}
point * passage::GetTop()
{
if(top == base)
{
cout<<"该堆栈为空。"<<endl;
return base;
}
else
{
return (top - 1);
}
}
passage & passage::Push(point e)
{
if((top - base)>=stacksize )
{
}
*top++= e;
return *this;
}
passage & passage::Pop()
{
if( top == base )
{
cout<<"该堆栈为空。"<<endl;
return *this;
}
top--;
return *this;
}
//输入迷宫阵 0 起始点,1 障碍物,2 通道,3 终点。
void InputMaze(int & maze[][], int size)
{
cout<<"*************输入迷宫阵*************"<<endl;
cout<<" 0 通道,1 障碍物,* 起始点,# 终点 "<<endl;
cout<<"************************************"<<endl;
for(int i=0; i<size; i++)
{
if(i != 0 && i != size-1 )
{
for(int j=0; j<size; j++)
{
if( j != 0 && j != size-1 )
{
cin>>maze[i][j];
}
else
{
maze[i][j]=1;
}
}
else
{
for(int j=0; j<size; j++)
maze[i][j]=1;
}
}
cout<<"-------------------------------------"<<endl;
}
//走迷宫
void FindPath( point maze[][], int size )
{
}
//输出找到的迷宫及通道
bool outputMaze(point maze[][], int size, bool ok )
{
if(ok)
{
for(int i=0; i<size; i++)
{
for(int j=0; j<size; j++)
{
cout<<maze[i][j].styl;
}
cout<<endl;
}
return true;
}
else
return false;
}
//测试
void main()
{
cout<<"**************迷宫测试**************"<<endl;
cout<<endl;
int maze[6][6];
InputMaze(maze[][], 6);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -