📄 page_621.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>page_621</title> <link rel="stylesheet" href="reset.css" type="text/css" media="all"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> <table summary="top nav" border="0" width="100%"> <tr> <td align="left" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_620.html">< previous page</a></td> <td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_621</strong></td> <td align="right" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_622.html">next page ></a></td> </tr> <tr> <td align="left" colspan="3" style="background: #ffffff; padding: 20px;"> <table border="0" width="100%" cellpadding="0"><tr><td align="center"> <table border="0" cellpadding="2" cellspacing="0" width="100%"><tr><td align="left"></td> <td align="right"></td> </tr></table></td></tr><tr><td align="left"><p></p><table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td align="right"><font face="Times New Roman, Times, Serif" size="2" color="#FF0000">Page 621</font></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">Because you don't know how many characters are in the list, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">charList</font><font face="Times New Roman, Times, Serif" size="3"> has to be large enough to hold all the characters in the character set except one. ('#' is a sentinel value and is not counted.) When </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">charList</font><font face="Times New Roman, Times, Serif" size="3"> has been read, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">counter</font><font face="Times New Roman, Times, Serif" size="3"> holds the length of the array; that is, when the list is searched for a character, only those components from </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">charList[0]</font><font face="Times New Roman, Times, Serif" size="3"> through </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">charList[length-1]</font><font face="Times New Roman, Times, Serif" size="3"> need be examined. This is another example of subarray processing. Note that </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">counter</font><font face="Times New Roman, Times, Serif" size="3"> is being used both as a counter and as an index.</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">Zero FreqList (parameters discussed later)</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table cellspacing="0" border="0" width="344" cellpadding="4"><tr><td valign="top"><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">FOR聽index聽going聽from聽0聽through聽length-1<br />聽聽Set聽freqList[index]聽=聽0</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table></td></tr></table><br /><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">Scan List (parameters discussed later)</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td height="12"></td></tr><tr><td><table cellspacing="0" border="0" width="476" cellpadding="4"><tr><td valign="top"><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">Set聽index聽=聽0<br />WHILE聽index聽<聽length聽AND聽inputChar聽!=聽charList[index]<br />聽聽聽Increment聽index<br />Set聽found聽=聽(index聽<聽length)</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table></td></tr></table></td></tr></table><br /><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">The algorithm for the Scan List module is called a <i>sequential search.</i> We start with the first array element and step through the array one element at a time. We continue searching until we either find the item we're looking for or reach the end of the array. If </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">found</font><font face="Times New Roman, Times, Serif" size="3"> is TRUE, the value of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">index</font><font face="Times New Roman, Times, Serif" size="3"> is the position in array </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">charList</font><font face="Times New Roman, Times, Serif" size="3"> where </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">inputChar</font><font face="Times New Roman, Times, Serif" size="3"> was found. If </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">inputChar</font><font face="Times New Roman, Times, Serif" size="3"> is not in the array, then </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">index</font><font face="Times New Roman, Times, Serif" size="3"> becomes equal to </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">length</font><font face="Times New Roman, Times, Serif" size="3">, and </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">found</font><font face="Times New Roman, Times, Serif" size="3"> is FALSE.</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">The While condition assumes the use of short-circuit evaluation of logical expressions (Chapter 5). If </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">index</font><font face="Times New Roman, Times, Serif" size="3"> equals </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">length</font><font face="Times New Roman, Times, Serif" size="3">, the condition is immediately determined to be FALSE. The second half of the condition is not evaluated (which would reference a nonexistent array element, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">charList[length]</font><font face="Times New Roman, Times, Serif" size="3">).</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">Increment FreqList</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table cellspacing="0" border="0" width="296" cellpadding="4"><tr><td valign="top"><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">Increment聽freqList[index]聽by聽1</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table></td></tr></table><br /></td></tr></table><p><font size="0"></font></p>聽 </td> </tr> <tr> <td align="left" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_620.html">< previous page</a></td> <td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_621</strong></td> <td align="right" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_622.html">next page ></a></td> </tr> </table> </body> </html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -