📄 用栈实现迷宫问题求解_数据结构与算法_数据结构算法_c语言_c 语言之家.htm
字号:
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 ord;<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"><SPAN
style="mso-tab-count: 1">
</SPAN>PostType seat;//</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>int di;<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">}SElemType;<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">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>SElemType* base;//</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">,</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>SElemType* top;//</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>int stackSize;<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">}Stack;<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 InitStack(Stack
&S){<SPAN style="mso-tab-count: 1">
</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"><FONT
face="Times New Roman">s<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>S.base=(SElemType*)malloc(INIT_SIZE
*sizeof(SElemType));<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>if(!S.base)<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>exit(OVERFLOW);//</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>S.top=S.base;<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>S.stackSize=INIT_SIZE;<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>return OK;<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">}//InitStack<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">Status StackEmpty(Stack
S){<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">//</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">s</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>if(S.top==S.base)<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>return TRUE;<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>return FALSE;<o:p></o:p></FONT></SPAN></P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -