⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ds3.3习题.htm

📁 这是清华大学所用的数据结构的电子版教材
💻 HTM
字号:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>数 据 结 构</title>
<meta name="Microsoft Theme" content="hounk 010">
</head>

<body background bgcolor="#000099" text="#CCCC99" link="#FF9900" vlink="#996600" alink="#FF3300">

<!--mstheme--><font face="宋体">

<p:colorscheme
 colors="#0000FF,#FFFFFF,#000000,#FFCC66,#00FFFF,#3366FF,#FF0033,#FFFF00"/>
<p align="center"><b><font face="oúì?,SimHei" lang="ZH-CN" color="#FFFFFF" size="6">第三章习题</font></b></p>
<p><font color="#FFFFFF"><span lang="EN-US"><b><font size="5">3.<span style="font-style: normal; font-variant: normal; font-family: Times New Roman"> 
</span></font></b></span><b><font size="5"><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
&quot;Times New Roman&quot;">设计一个算法判别一个算术表达式的圆括号是否正确配对。</span></font></b></font></p>
<p class="MsoNormal" align="left"><font color="#FFFFFF"><b><font size="5"><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;
mso-hansi-font-family:&quot;Times New Roman&quot;">解答1:</span></font></b></font></p> 
 
<p class="MsoNormal" align="left"><b><font size="5" color="#FFFFFF"><span lang="EN-US" style="mso-bidi-font-size:10.0pt;font-family:&quot;Times New Roman&quot;">Status 
Bracket_Test1(char *str)</span><span lang="EN-US" style="mso-bidi-font-size:10.0pt;font-family:&quot;Times New Roman&quot;"><br>
{<br>
&nbsp;&nbsp;count=0;<br>
&nbsp;&nbsp;for(p=str;*p;p++)<br>
&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;if(*p=='(') count++;<br> 
&nbsp;&nbsp;&nbsp;&nbsp;else if(*p==')') count--;<br> 
&nbsp;&nbsp;&nbsp;&nbsp;if (count&lt;0) return ERROR;<br> 
&nbsp;&nbsp;}<br>
&nbsp;&nbsp;if(count) return ERROR; //</span><span style="mso-bidi-font-size: 
10.0pt;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;">注意括号不匹配的两种情况</span><span lang="EN-US" style="mso-bidi-font-size:10.0pt;font-family:&quot;Times New Roman&quot;"><br>
&nbsp;&nbsp;return OK;<br> 
}//Bracket_Test&nbsp;</span></font></b></p> 
 
<p class="MsoNormal" align="left"><font color="#FFFFFF"><b><font size="5"><span style="font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;
mso-hansi-font-family:&quot;Times New Roman&quot;">解答2:</span></font></b></font></p> 
 
<p class="MsoNormal" align="left" style="margin-top: 0; margin-bottom: 0"><font size="5" color="#FFFFFF"><b><span style="font-family: 宋体; mso-ascii-font-family: Times New Roman; mso-hansi-font-family: Times New Roman">int 
Bracket_test2(char *str,</span></b><b>SeqStack *s</b><b><span style="font-family: 宋体; mso-ascii-font-family: Times New Roman; mso-hansi-font-family: Times New Roman">)</span></b></font></p> 
 
<p class="MsoNormal" align="left" style="margin-top: 0; margin-bottom: 0"><b><font size="5" color="#FFFFFF"><span lang="EN-US" style="mso-bidi-font-size:10.0pt;font-family:&quot;Times New Roman&quot;"><o:p>
</o:p>
{</span></font></b></p> 
 
<p class="MsoNormal" align="left" style="margin-top: 0; margin-bottom: 0">&nbsp;  
<font size="5" color="#FFFFFF"><b>for(p=str;*p!='\0';p++)</b></font></p> 
 
<p class="MsoNormal" align="left" style="margin-top: 0; margin-bottom: 0"><font size="5" color="#FFFFFF"><b>&nbsp;{</b></font></p> 
 
<p class="MsoNormal" align="left" style="margin-top: 0; margin-bottom: 0"><font size="5" color="#FFFFFF"><b>&nbsp;&nbsp;  
if(*p=='(') push(s,*p);</b></font></p>  
 
<p class="MsoNormal" align="left" style="margin-top: 0; margin-bottom: 0"><font size="5" color="#FFFFFF"><b>&nbsp;&nbsp;  
if(*p==')')</b></font></p> 
 
<p class="MsoNormal" align="left" style="margin-top: 0; margin-bottom: 0"><font size="5" color="#FFFFFF"><b>&nbsp;&nbsp;&nbsp;&nbsp;  
if(!Empty_stack(s)) pop(s);</b></font></p>  
 
<p class="MsoNormal" align="left" style="margin-top: 0; margin-bottom: 0"><font size="5" color="#FFFFFF"><b>&nbsp;&nbsp;&nbsp;&nbsp;  
else return 0;&nbsp;&nbsp;&nbsp;</b></font></p>  
 
<p class="MsoNormal" align="left" style="margin-top: 0; margin-bottom: 0"><font size="5" color="#FFFFFF"><b>&nbsp;}</b></font></p> 
 
<p class="MsoNormal" align="left" style="margin-top: 0; margin-bottom: 0">&nbsp;<font size="5" color="#FFFFFF"><b> 
if(!Empty_stack(s)||*p!='\0') return 0;</b></font></p>  
 
<p class="MsoNormal" align="left" style="margin-top: 0; margin-bottom: 0"><font size="5" color="#FFFFFF"><b>&nbsp;  
return 1;</b></font></p>  
 
<p class="MsoNormal" align="left" style="margin-top: 0; margin-bottom: 0"><span lang="EN-US" style="mso-bidi-font-size:10.0pt;font-family:&quot;Times New Roman&quot;"><b><font size="5" color="#FFFFFF">}</font></b></span></p> 
 
<p class="MsoNormal" align="center"><a href="ds3习题.HTM"><b><font size="5" color="#FFFF00">返回</font></b></a></p> 
 
<!--mstheme--></font> 
 
</body> 
 
</html> 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -