📄 用栈实现迷宫问题求解_数据结构与算法_数据结构算法_c语言_c 语言之家.htm
字号:
style="FONT-SIZE: 9pt"><FONT
face="Times New Roman">#define MAXLEN
10//</FONT></SPAN><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">迷宫包括外墙最大行列数目</SPAN><SPAN
lang=EN-US
style="FONT-SIZE: 9pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US
style="FONT-SIZE: 9pt"><FONT
face="Times New Roman">typedef
struct{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US
style="FONT-SIZE: 9pt"><FONT
face="Times New Roman"><SPAN
style="mso-tab-count: 1">
</SPAN>int r;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US
style="FONT-SIZE: 9pt"><FONT
face="Times New Roman"><SPAN
style="mso-tab-count: 1">
</SPAN>int c;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US
style="FONT-SIZE: 9pt"><FONT
face="Times New Roman"><SPAN
style="mso-tab-count: 1">
</SPAN>char
adr[MAXLEN][MAXLEN];//</FONT></SPAN><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可取</SPAN><SPAN
lang=EN-US style="FONT-SIZE: 9pt"><FONT
face="Times New Roman">' ''*' '@'
'#'<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US
style="FONT-SIZE: 9pt"><FONT
face="Times New Roman">}MazeType;<SPAN
style="mso-spacerun: yes">
</SPAN>//</FONT></SPAN><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">迷宫类型</SPAN><SPAN
lang=EN-US
style="FONT-SIZE: 9pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US
style="FONT-SIZE: 9pt"><FONT
face="Times New Roman">Status InitMaze(MazeType
&maze){<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"><SPAN
lang=EN-US style="FONT-SIZE: 9pt"><FONT
face="Times New Roman">//</FONT></SPAN><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">初始化迷宫若成功返回</SPAN><SPAN
lang=EN-US style="FONT-SIZE: 9pt"><FONT
face="Times New Roman">TRUE,</FONT></SPAN><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">否则返回</SPAN><SPAN
lang=EN-US style="FONT-SIZE: 9pt"><FONT
face="Times New Roman">FALSE<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US
style="FONT-SIZE: 9pt"><FONT
face="Times New Roman"><SPAN
style="mso-tab-count: 1">
</SPAN>int m,n,i,j;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US
style="FONT-SIZE: 9pt"><FONT
face="Times New Roman"><SPAN
style="mso-tab-count: 1">
</SPAN>printf("Enter row and column numbers:
");<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US
style="FONT-SIZE: 9pt"><FONT
face="Times New Roman"><SPAN
style="mso-tab-count: 1">
</SPAN>scanf("%d%d",&maze.r,&maze.c);
//</FONT></SPAN><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">迷宫行和列数</SPAN><SPAN
lang=EN-US
style="FONT-SIZE: 9pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US
style="FONT-SIZE: 9pt"><FONT
face="Times New Roman"><SPAN
style="mso-tab-count: 1">
</SPAN>for(i=0;i<=maze.c+1;i++){//</FONT></SPAN><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">迷宫行外墙</SPAN><SPAN
lang=EN-US
style="FONT-SIZE: 9pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US
style="FONT-SIZE: 9pt"><FONT
face="Times New Roman"><SPAN
style="mso-tab-count: 2">
</SPAN>maze.adr[0][i]='#';<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US
style="FONT-SIZE: 9pt"><FONT
face="Times New Roman"><SPAN
style="mso-tab-count: 2">
</SPAN>maze.adr[maze.r+1][i]='#';<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US
style="FONT-SIZE: 9pt"><FONT
face="Times New Roman"><SPAN
style="mso-tab-count: 1">
</SPAN>}//for<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US
style="FONT-SIZE: 9pt"><FONT
face="Times New Roman"><SPAN
style="mso-tab-count: 1">
</SPAN>for(i=0;i<=maze.r+1;i++){//</FONT></SPAN><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">迷宫列外墙</SPAN><SPAN
lang=EN-US
style="FONT-SIZE: 9pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US
style="FONT-SIZE: 9pt"><FONT
face="Times New Roman"><SPAN
style="mso-tab-count: 2">
</SPAN>maze.adr[i][0]='#';<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US
style="FONT-SIZE: 9pt"><FONT
face="Times New Roman"><SPAN
style="mso-tab-count: 2">
</SPAN>maze.adr[i][maze.c+1]='#';<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US
style="FONT-SIZE: 9pt"><FONT
face="Times New Roman"><SPAN
style="mso-tab-count: 1">
</SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US
style="FONT-SIZE: 9pt"><FONT
face="Times New Roman"><SPAN
style="mso-tab-count: 1">
</SPAN>for(i=1;i<=maze.r;i++)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US
style="FONT-SIZE: 9pt"><FONT
face="Times New Roman"><SPAN
style="mso-tab-count: 2">
</SPAN>for(j=1;j<=maze.c;j++)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US
style="FONT-SIZE: 9pt"><FONT
face="Times New Roman"><SPAN
style="mso-tab-count: 3">
</SPAN>maze.adr[i][j]=' ';//</FONT></SPAN><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">初始化迷宫</SPAN><SPAN
lang=EN-US
style="FONT-SIZE: 9pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US
style="FONT-SIZE: 9pt"><FONT
face="Times New Roman"><SPAN
style="mso-tab-count: 1">
</SPAN>printf("Enter block's coordinate((-1,-1) to
end): ");<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US
style="FONT-SIZE: 9pt"><FONT
face="Times New Roman"><SPAN
style="mso-tab-count: 1">
</SPAN>scanf("%d%d",&m,&n);//</FONT></SPAN><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">接收障碍的坐标</SPAN><SPAN
lang=EN-US
style="FONT-SIZE: 9pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -