马踏棋盘问题
只能执行到第二步,找不出结果,求各位帮忙#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
typedef struct Point{
int x;
int y;
int e;
}Point;
typedef struct {
Point *base;
Point *top;
int stacksize;
}SqStack;
int InitStack(SqStack *S)
{
(*S).base =(Point *)malloc(STACK_INIT_SIZE*sizeof(Point));
if(!(*S).base)exit(1);
(*S).top = (*S).base;
(*S).stacksize = STACK_INIT_SIZE;
return 1;
}
int StackEmpty(SqStack *S)
{
if((*S).top==(*S).base)
return 1;
else
return 0;
}
int Push(SqStack *S,Point e)
{
if((*S).top - (*S).base >= (*S).stacksize)
{
(*S).base =(Point *)realloc((*S).base,((*S).stacksize+STACKINCREMENT) * sizeof(Point));
if(!(*S).base)exit(1);
(*S).top = (*S).base+(*S).stacksize;
(*S).stacksize += STACKINCREMENT;
}
*(*S).top++ = e;
return 1;
}
int Pop(SqStack *S, Point *e)
{
if((*S).top ==(*S).base) return 0;
*e = * --(*S).top;
return 1;
}
int SetTop(SqStack S,Point *e)
{
if(S.top>S.base)
{
*(S.top-1)=*e;
return 1;
}
else
return 0;
}
void main()
{
Point e;
int count=1;
int i,j;
int board[8][8]={{0}};
int x1,y1;
int move1[8]={2,2,1,1,-1,-1,-2,-2,},
move2[8]={1,-1,2,-2,2,-2,1,-1,};
int pic[8][8]; //对应棋盘
SqStack S;
for(i=0;i<8;i++)
for(j=0;j<8;j++)
pic[i][j]=0;
//输入入口点,并让其进栈
printf("输入x1(0-7),y1(0-7):");
scanf("%d%d",&x1,&y1);
e.x=x1;
e.y=y1;
pic[x1][y1]=1;
InitStack(&S);
Push(&S,e);
int k=0;
while(count!=64)
{
if(x1+move1[k]>0&&x1+move1[k]<=8&&y1+move2[k]>0&&y1+move2[k]<=8&&board[x1+move1[k]][y1+move2[k]]==0)
{
pic[x1+move1[k]][y1+move2[k]]=++count;
e.x=x1+move1[k];
e.y=y1+move2[k];
Push(&S,e);
k=0;
}
else
board[x1+move1[k]][y1+move2[k]]=1;
k++;
}
while(!StackEmpty(&S))
{
Pop(&S,&e);
printf("(%d %d)",e.x,e.y);
}
printf("\n");
/* 打印出马走棋盘的路线*/
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
printf("%d\t",pic[i][j]);
printf("\n\n\n");
}
}