it stopped with signal SIGSEGV,Segmentation fault
windows.h stdio.h stdlib.h stdio.h
-----------------------------------------------------以下正文
int xnum;
int ynum;
int a[100][100];
#define X0 100
#define Y0 100
#define WIDTH 20
typedef struct
{
int x;
int y;
}NODE;
typedef struct
{
NODE nownode;
NODE prenode;
int dir;
}GRID;
NODE start;
NODE end;
GRID grid;
//-------------------------------顺序栈
class Stack
{
private:
int size;
public:
NODE *p;
int top;
Stack(int n=0);
~Stack();
bool isEmpty();
bool isFull();
bool push(const NODE k);
bool pop();
};
Stack::Stack(int n)
{
p=0;
if(n>0)
p=new NODE[n];
size=n;
top=-1;
}
Stack::~Stack(){
delete []p;
size=0;
top=-1;
}
bool Stack::isEmpty(){
return(top==-1);
}
bool Stack::isFull(){
return(top>=size-1);
}
bool Stack::push(const NODE k){
if(!isFull()){
top++;
p[top]=k;
return true;
}
return false;
}
bool Stack::pop(){
if(!isEmpty()){
NODE k=p[top];
top--;
return 1;
}
return 0;
}
//。-----------------------------画框
void Init()
{
FILE* fp;
fp=fopen("mice.txt","r");
fscanf(fp,"%d%d%d%d%d%d",&xnum,&ynum,&start.x,&start.y,&end.y,&end.x);//24 24 1 1 24 1
int i,j;
for(j=0;j<=ynum+1;j++)
for(i=0;i<=xnum+1;i++)
a[j][i]=1;
for(j=1;j<=ynum;j++)
for(i=1;i<=xnum;i++)
fscanf(fp,"%d",&a[j][i]);
fclose(fp);
grid.nownode =start;//--------------初始位置 (1,1)
}
void reaction(Stack path,int x,int y){
grid.nownode.x=x;
grid.nownode.y=y;
path.push(grid.nownode);
//PrintNum(120,50,grid.nownode.x);
//PrintNum(140,50,grid.nownode.y);
//DrawRectangle(X0+grid.nownode.y*WIDTH,Y0+grid.nownode.x*WIDTH,X0+(grid.nownode.y+1)*WIDTH,Y0+(grid.nownode.x+1)*WIDTH,MOUSECOLOR);
}
int MouseMove(Stack path)
{
int x,y;
x=grid.nownode.x;
y=grid.nownode.y;//--------------现在位置
if (end.x==x && end.y==y){
grid.nownode.x=x;
grid.nownode.y=y;
path.push(grid.nownode);
return 1;
}
else{
a[x][y]=1;//------------------------------------------------似乎指出的是这里
if(a[x][y+1]==0)
reaction(path,x,y+1);
else if(a[x+1][y]==0)
reaction(path,x+1,y);
else if(a[x][y-1]==0)
reaction(path,x,y-1);
else if(a[x-1][y]==0)
reaction(path,x-1,y);
else
{
path.pop();
grid.nownode.x=path.p[path.top].x; //上一个值作现在位置
grid.nownode.y=path.p[path.top].y;
}
}
return 0;
}
int main(){
Init();
Stack path(2000); //---------------------//创建顺序表
path.push(start);
int x,y;
x=grid.nownode.x;
y=grid.nownode.y;//--------------现在位置
while(end.x!=x || end.y!=y)
MouseMove(path);
for(int i=0; i<=path.top;i++)
a[path.p[path.top].x][path.p[path.top].y]=2;
for(int i=0;i<=xnum+1;i++)
{
for(int j=0;j<=ynum+1;j++)
printf("%d",a[i][j]);
printf("\n");
}
scanf("%d",&x);
return 0;
}
---------------------------------------------------mice.txt文件 (迷宫问题 C-FREE下)
24 24 1 1 24 1
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 0 0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