c++迷宫问题求帮助!error C2784: 'bool __cdecl std::operator ==(const class std::istream_it
发布网友
发布时间:2022-04-29 14:54
我来回答
共1个回答
热心网友
时间:2023-10-13 02:47
楼主,错误如下:
1.
// e=(curstep,curpos,1); //改为下面3行的内容
e.ord=curstep; ////定义的postype e; 只是postype的对象,应该调用postype里面的成员进行赋值,上面错误的写法是函数赋值
e.seat=curpos; ////
e.di=1; ////
2.
// if(curpos==end) return true; //改为下面1行的内容
if(curpos.x==end.x && curpos.y==end.y) return true; //原因同上,应该调用coordinate里面的成员才能进行比较
还有二维数组的写法问题,具体的说在程序里,看看吧:
#include <iostream>
#include <stack>
#include <malloc.h>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
#define n 10
int a[n][n]={{0,0,0,0,0,0,0,0,0,0}, //二维数组应该这样写,小数组里也该用括号
{0,1,1,0,1,1,1,0,1,0},
{0,1,1,0,1,1,1,0,1,0},
{0,1,1,1,1,0,0,1,1,0},
{0,1,0,0,0,1,1,1,1,0},
{0,1,1,1,0,1,1,1,1,0},
{0,1,0,1,1,1,0,1,1,0},
{0,1,0,0,0,1,0,0,1,0},
{0,0,1,1,1,1,1,1,1,0},
{0,0,0,0,0,0,0,0,0,0}
};
int b[n][n];
typedef struct
{
int x;
int y;
}coordinate;
typedef struct
{
int ord;
coordinate seat;
int di;
}postype;
bool pass(coordinate epos)
{
if(b[epos.x][epos.y]==1) return true;
else return false;
}
void footprint(coordinate curpos)
{
b[curpos.x][curpos.y]=0;
}
coordinate nextpos(coordinate curpos,int t)
{
switch (t)
{
case 1: curpos.x++;
case 2: curpos.y++;
case 3: curpos.x--;
case 4: curpos.y--;
}
return curpos;
}
bool mazepath(coordinate start,coordinate end)
{
postype e;
stack<postype> pos;
coordinate curpos;
curpos=start;
int curstep=1;
do
{
if(pass(curpos))
{
footprint(curpos);
// e=(curstep,curpos,1); //改为下面3行的内容
e.ord=curstep; ////定义的postype e; 只是postype的对象,应该调用postype里面的成员进行赋值,上面错误的写法是函数赋值
e.seat=curpos; ////
e.di=1; ////
pos.push(e);
// if(curpos==end) return true; //改为下面1行的内容
if(curpos.x==end.x && curpos.y==end.y) return true; //原因同上,应该调用coordinate里面的成员才能进行比较
curpos=nextpos(curpos,1);
curstep++;
}
else
{
if(!pos.empty())
{
pos.pop();
while (e.di==4&&!pos.empty())
{
footprint(e.seat);
pos.pop();
}
if(e.di<4)
{
e.di++;
pos.push(e);
curpos=nextpos(e.seat,e.di);
}
}
}
}while(!pos.empty());
return false;
}
void main()
{
coordinate start,end;
int i,j;
b[n][n]=a[n][n];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
cout<<a[i][j]<<" ";
cout<<endl;
}
start.x=1; start.y=1;
end.x=8; end.y=8;
mazepath(start,end);
}