这里写了关于迷宫求路径问题的代码
#pragma once
#include<iostream>
#include<assert.h>
#include<stdio.h>
#include<stack>
const size_t N = 10;
using namespace std;
void InitMaze(int Maze[][N],size_t n)
{
FILE* fout = fopen("Maze.txt", "x");
assert(fout);
for (size_t i = 0; i < n; ++i)
{
for (size_t j = 0; j < n;)
{
char ch = fgetc(fout);
if (ch == '0' || ch == '1')
{
Maze[i][j] = ch - '0';
++j;
}
}
}
}
void PrintMaze(int Maze[][N],size_t n)
{
for (size_t i = 0; i < n; ++i)
{
for (size_t j = 0; j < n; ++j)
{
cout << Maze[i][j];
}
cout << endl;
}
cout << endl;
}
struct Pos
{
int _r;
int _c;
};
bool CheckPath(int Maze[][N],size_t n,Pos Acc)
{
if (Acc._r < n && Acc._c >= 0 && Acc._c < n && Acc._r >= 0 && Maze[Acc._r][Acc._c] == 0)
{
return true;
}
return false;
}
bool GetSPath(int Maze[][N], size_t n, Pos entry)
{
stack<Pos