这是一个迷宫求解的部分程序,运行后老是有错误,请诸位帮忙看看,改正一下!
E:\新建文件夹\cfc.cpp(40) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'struct lnode *' (or there is no acceptable conversion)上面是运行后出现的错误,下面是代码。
#include"stdio.h"
#include"malloc.h"
#define m 8
#define n 10
typedef struct
{
int x;
int y;
int d;
}elemtype;
typedef struct
{
int x;
int y;
}item;
typedef struct lnode
{
elemtype data;
struct lnode *next;
}seqstack;
int Empty_seqstack (seqstack& s )
{
if(s==NULL)
return 1;
else
return 0;
}
int push_seqstack (seqstack &s, elemtype& temp )
{
seqstack *p;
p=(seqstack*)malloc(sizeof(seqstack));
p->data=temp;
p->next=s;
s=p;
return 1;
}
int pop_seqstack (seqstack &s, elemtype& temp )
{
seqstack *q;
if(Empty_seqstack(s))
return 0;
else
q=s;
temp=q->data;
s=q->next;
free(q);
return 1;
}
int path(int maze[m][n], item move[4])
{ seqstack s ;
elemtype temp ;
int x, y, d, i, j ;
temp.x=1; temp.y=1;
temp.d=-1;
push_seqstack (s,temp);
while (! Empty_seqstack (s ) )
{
pop_seqstack (s,temp) ;
x=temp.x ;
y=temp.y ;
d=temp.d+1 ;
while (d<4)
{ i=x+move[d].x ;
j=y+move[d].y ;
if ( maze[i][j]==0 )
{
temp.x=x;
temp.y=y;
temp.d=d;
push_seqstack ( s, temp ) ;
x=i;
y=j;
maze[x][y]= -1 ;
if (x==m&&y==n)
return 1;
else
d=0 ;
}
else
d++ ;
}
}
return 0;
}
int main()
{
seqstack s;
int i,j,k;
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("迷宫与栈问题");
int maze[m][n]={
1,1,1,1,1,1,1,1,1,1,
1,0,0,1,1,1,1,1,1,1,
1,1,0,1,0,1,1,1,1,1,
1,1,0,0,0,0,0,0,1,1,
1,0,1,1,1,0,1,1,1,1,
1,1,0,0,1,0,0,0,0,1,
1,0,1,1,0,1,1,1,0,1,
1,1,1,1,1,1,1,1,1,1,
};
item move[4]={{1,0},{0,1},{-1,0},{0,-1}};
path(maze,move);
return 0;
}