📄 用栈实现迷宫问题求解_数据结构与算法_数据结构算法_c语言_c 语言之家.htm
字号:
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US
style="FONT-SIZE: 9pt"><FONT
face="Times New Roman">}//StackEmpty<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 Push(Stack
&S,SElemType e){<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"><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"><FONT
face="Times New Roman">e</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>if(S.top-S.base
>=S.stackSize){//</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>S.base=(SElemType
*)realloc(S.base,(S.stackSize+INCREMENT)*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: 2">
</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: 3">
</SPAN>exit(OVERFLOW);<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: 2">
</SPAN>S.top=S.base+S.stackSize;<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>S.stackSize+=INCREMENT;<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>*S.top++=e;<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">}//push<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-char-indent-count: -2.0"><SPAN
lang=EN-US style="FONT-SIZE: 9pt"><FONT
face="Times New Roman">Status Pop(Stack
&S,SElemType &e){//</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"><FONT
face="Times New Roman">e</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">OK</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">ERROR<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 ERROR;<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>e=*--S.top;<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">}//Pop<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 DestroyStack(Stack
&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">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>free(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.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>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">}//DestroyStack<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US
style="FONT-SIZE: 9pt"><o:p><FONT
face="Times New Roman"> </FONT></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">//maze.cpp<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">#include
"stack.h"<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -