#include<stdio.h>
#include<stdlib.h>
#define stack_size 100
#define n 8
int a[n][n];
int sort[n][n][8];
int i, j, k,h,l;
struct seat
{
int x, y;//坐标
int direct;
};
struct stack
{
struct seat *top, *base;
};
struct stack s;
int initstack()
{
s.base=(struct seat*)malloc( stack_size*sizeof(struct seat) );
if( !s.base )
return 0;
s.top=s.base;
return 1;
}
void push(struct seat elem)
{
*s.top++=elem;
}
int pop()
{
if(s.top==s.base)
return 0;
s.top--;
return 1;
}
struct seat gettop()
{
if(s.top==s.base)
exit(0);
return *(s.top-1);
}
int empty()
{
if(s.top==s.base)
return 0;
return 1;
}
int pass(struct seat point)
{
struct seat *head=s.top;
if(point.x<0 || point.x>n-1 || point.y<0 || point.y>n-1)
{
return 0;
}
while(head != s.base)
{
head--;
if(point.x==head->x && point.y==head->y)
return 0;
}
return
C语言:马踏棋盘,改编自《数据结构与算法》.
最新推荐文章于 2021-05-17 10:59:57 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)