c语言迷宫栈,学了栈,做了一个迷宫程序。

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

#include

#include

#include

#define NULL 0

struct maze

{

struct maze *prior;

int x;

int y;

int dir;

struct maze *next;

};

int cmp(struct maze *head,struct maze *q)

{

struct maze *p;

int i=1;

p=head;

while(p->x!=q->x||p->y!=q->y)

p=p->next;

if(p==q)

return(1);

else

return(0);

}

void main()

{

int a[10][10],X,Y,i,j,in_x,in_y,out_x,out_y;

double t1,t2;

struct maze *head,*p,*q;

printf("scale:\n");

scanf("%d %d",&X,&Y);

printf("maze consisting of 0 (accessible) and 1 (inaccessible):\n");

for(i=0;i

{

for(j=0;j

scanf("%d",&a[i][j]);

}

printf("in:\n");

scanf("%d %d",&in_x,&in_y);

printf("out:\n");

scanf("%d %d",&out_x,&out_y);

t1=clock();

head=(struct maze *)malloc(sizeof(struct maze));

head->prior=NULL;

p=head;

q=p;

p->x=in_x-1;

p->y=in_y-1;

p->dir=1;

loop:

do

{

q=(struct maze *)malloc(sizeof(struct maze));

p->next=q;

q->prior=p;

q->dir=1;

switch(p->dir)

{

case 1:q->x=p->x+1;q->y=p->y;break;

case 2:q->x=p->x;q->y=p->y+1;break;

case 3:q->x=p->x-1;q->y=p->y;break;

case 4:q->x=p->x;q->y=p->y-1;break;

default:

free(q);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值