数据结构毕业课程设计报告迷宫求解问题文档格式.docx
- 文档编号:13192040
- 上传时间:2022-10-08
- 格式:DOCX
- 页数:21
- 大小:27.23KB
数据结构毕业课程设计报告迷宫求解问题文档格式.docx
《数据结构毕业课程设计报告迷宫求解问题文档格式.docx》由会员分享,可在线阅读,更多相关《数据结构毕业课程设计报告迷宫求解问题文档格式.docx(21页珍藏版)》请在冰豆网上搜索。
初始条件:
已初始化栈S,且栈为空
操作结果:
从栈S中找出相对应的数据关系,并输出结果
}ADTFind
2.主程序的流程以及各程序模块之间的调用关系:
(1).定义变量i、j、w、z为整形变量
(2).输入迷宫二维数组maze(0:
m,0:
n)
(3).调用子程序find()
(4).结束程序
三、相应的源程序如下:
#include<
stdio.(void)
{
SqStackS;
intsize,maze[12][12];
for(intn=0;
n<
10;
n++)
{
printf("
创建一个正方形迷宫,请输入迷宫尺寸(注意不要大于50):
\n"
);
scanf("
%d"
&
size);
if(size<
1||size>
10){printf("
输入错误!
"
return;
}
Initmaze(maze,size);
printmaze(maze,size);
PosTypestart,end;
输入入口行坐标和列坐标:
scanf("
start.row);
start.line);
输入出口行坐标和列坐标:
end.row);
end.line);
if(MazePath(maze,S,start,end))
printpath(maze,S,size);
elseprintf("
找不到通路!
\n\n"
StatusMazePath(intmaze[12][12],SqStack&
S,PosTypestart,PosTypeend)
PosTypecurpos;
intcurstep;
SElemTypee;
InitStack(S);
curpos=start;
curstep=1;
do{
if(Pass(maze,curpos))
{
Markfoot(maze,curpos);
e.di=1;
e.ord=curstep;
e.seat=curpos;
Push(S,e);
if(curpos.row==end.row&
&
curpos.line==end.line)
returnOK;
curpos=NextPos(curpos,1);
curstep++;
}
else
{
if(!
StackEmpty(S))
Pop(S,e);
while(e.di==4&
!
Markfoot(maze,e.seat);
if(e.di<
4)
e.di++;
Push(S,e);
curpos=NextPos(e.seat,e.di);
}while(!
StackEmpty(S));
returnERROR;
}
voidInitmaze(intmaze[12][12],intsize)
charselect;
printf("
选择创建方式A:
自动生成B:
手动创建\n"
label:
%c"
select);
if(select=='
a'
||select=='
A'
)
for(inti=0;
i<
size+2;
i++)maze[0][i]=1;
for(i=1;
size+1;
i++)
maze[i][0]=1;
for(intj=1;
j<
j++)
maze[i][j]=rand()%2;
maze[i][size+1]=1;
}
for(i=0;
i++)maze[size+1][i]=1;
elseif(select=='
b'
B'
按行输入%d*%d数据,0代表可通,1代表不可通(每行以Enter结束):
size,size);
maze[i][j]);
\n'
)gotolabel;
voidprintmaze(intmaze[12][12],intsize)
显示所建的迷宫(#表示外面的墙):
i++)printf("
%c"
'
#'
for(i=1;
%d"
maze[i][j]);
voidprintpath(intmaze[12][12],SqStackS,intsize)
\n\n通路路径为:
SElemType*p=S.base;
while(p!
=S.top)
maze[p->
seat.row][p->
seat.line]=2;
p++;
if(maze[i][j]==2)printf("
0'
"
StatusPass(intmaze[12][12],PosTypeCurPos)
if(maze[CurPos.row][CurPos.line]==0)
elsereturnERROR;
voidMarkfoot(intmaze[12][12],PosTypeCurPos)
maze[CurPos.row][CurPos.line]=1;
PosTypeNextPos(PosTypeCurPos,intDir)
PosTypeReturnPos;
switch(Dir)
case1:
ReturnPos.row=CurPos.row;
ReturnPos.line=CurPos.line+1;
break;
case2:
ReturnPos.row=CurPos.row+1;
ReturnPos.line=CurPos.line;
case3:
ReturnPos.line=CurPos.line-1;
case4:
ReturnPos.row=CurPos.row-1;
returnReturnPos;
StatusInitStack(SqStack&
S.base=(SElemType*)malloc(100*sizeof(SElemType));
if(!
S.base)returnERROR;
S.top=S.base;
S.stacksize=100;
returnOK;
StatusPush(SqStack&
S,SElemType&
a)
*S.top++=a;
StatusPop(SqStack&
if(S.top==S.base)returnERROR;
a=*--S.top;
StatusStackEmpty(SqStackS)
if(S.top==S.base)returnOK;
以下为测试数据:
输入一个矩阵,例如:
10011
00111
10001
01011
11000
输入入口行坐标和列坐标:
12
输入出口行坐标和列坐标:
55
通路路径为:
课题设计3:
joseph环
利用单向循环链表存储结构模拟此过程,按照出列的顺序输出各个人的编号。
首先创建一个空链表,初始化链表,构造出一个只有头结点的空链表,建立好一个约瑟夫环。
1.输入的形式和输入值的范围
本程序中,输入报数上限值m和人数上限l,密码,均限定为正整数,输入的形式为一个以“回车符”为结束标志的正整数。
2.输出的形式
从屏幕显示出列顺序。
3.程序功能
提供用户从键盘输入,Joseph约瑟夫环的必要数据,并显示出列顺序。
二、
概要设计
以单向循环链表实现该结构。
1.抽象数据类型的定义为:
ADTLNode
D={ai|ai∈CharSet,i=1,2,…,n,n≥0}
R1={&
lt;
ai-1,ai&
gt;
|ai∈D,I=2,…,n}
三.源程序:
stdio.,Link&
L)初始化链表
Linkp,q;
q=L;
for(inti=1;
=n;
i++)
p=(Node*)malloc(sizeof(Node));
if(!
p)
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构 毕业 课程设计 报告 迷宫 求解 问题
![提示](https://static.bdocx.com/images/bang_tan.gif)