求助,谁帮我看看

shangxin2856 2003-03-19 10:13:46
#difine STACK_INIT_SIZE 100
#difine STACKINCREMENT 10
typedef struct
{int x;
int y;
}postype;
typedef struct
{int ord;
postype seat;
int di;
}selemtype;
typedef struct
{selemtype *base;
selemtype *top;
int stacksize;
}sqstack;
sqstack *s;
postype start,end,curpos;
int a[10][10];
start.x=1;
start.y=1;
end.x=8;
end.y=8;
ininarray()
{int i,j;
for(i=1;i<9;i++)
for(j=1;j<9;j++)
if(i==0||i==9||j==0||j==9)a[i][j]=0;
a[1][3]=0;
a[1][7]=0;
a[2][3]=0;
a[2][7]=0;
a[3][5]=0;
a[3][6]=0;
a[4][2]=0;
a[4][3]=0;
a[4][4]=0;
a[5][4]=0;
a[6][2]=0;
a[6][6]=0;
a[7][2]=0;
a[7][3]=0;
a[7][4]=0;
a[7][6]=0;
a[7][7]=0;
a[8][1]=0;
}
initstack()
{s.base=(selemtype*)malloc(STACK_INIT_SIZE*sizeof(selemtype));
if(!s.base)exit(0);
s.top=s.base;
s.stacksize=STACK_INIT_SIZE;
}
push(sqstack *s,selemtype e)
{if(s.top-s.base>=s.stacksize)
{s.base=(selemtype*)realloc(s.base,(s.stacksize+STACKINCREMENT)*sizeof(selemtype);
if(!s.base)exit(0);
s.top=s.base+s.stacksize;
s.stacksize+=STACKINCREMENT;
}
*s.top++=e;
}
pop(sqstack *s,selemtype e)
{if(s.top==s.base)exit(0);
e=*--s.top;
}
stackempty(sqstack s)
{if(s.top==s.base)return 1;
else return 0;
}
nextpos(int i)
{ switch(i)
{
case 1:(e.seat.y)++;break;
case 2:(e.seat.x)--;break;
case 3:(e.seat.y)--;break;
case 4:(e.seat.x)++;break;
default :break;
}
}
footprint(pos i)
{
a[i.x][i.y]=e.dir;
}

mazepath()
{
selemtype e;
initstack();
curpos=start;
curstep=1;
do{
if(pass(curpos))
{
footprint(e.seat);
e=(curstep,curpos,1);
push(s,e);
if(curpos==end)return 1;
curpos=nexrpos(curpos,1);
curstep++;
}
else
{if(!stackempty(s))
{pop(s,e);
while(e.di==4&&!stackempty(s))
{footprint(e.seat);
pop(s,e);
}
if(e.di<4)
{e.di++;
push(s,e);
curpos=nextpos(e.seat,e.di);
}
}
}
}while(!stackempty(s));
return 0;
}
main()
{int i,j;
initarray()
if(mazepath())
for(i=1;i<9:i++)
for(j=1;j<9;j++)
if(a[i][j]==9)printf("(%d,%d)",i,j);
else printf("the mazepath is a impossible problem!");
}





...全文
47 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
ww2003 2003-03-20
  • 打赏
  • 举报
回复
up
dahuzizyd 2003-03-20
  • 打赏
  • 举报
回复
看的我头晕,帮你顶一下
cenlmmx 2003-03-20
  • 打赏
  • 举报
回复
程序太长,没有任何注释,没有问题阐述.
够呛
hyhu 2003-03-20
  • 打赏
  • 举报
回复
对啊,你的宏定义错了!
song0320 2003-03-20
  • 打赏
  • 举报
回复
difine 是什么啊

是不是define啊

cyicecream 2003-03-20
  • 打赏
  • 举报
回复
问题呢?不是来散分的吧:P
huigll 2003-03-20
  • 打赏
  • 举报
回复
没有办法!
你从基础的东西开始学起吧!
bm1408 2003-03-20
  • 打赏
  • 举报
回复
把你程序要实现的东东写出来,以及有什么问题!
这样写出个程序来,干什么呢?
想帮你都没有办法帮你!

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧