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

📄 page_948.html

📁 Programming and Problem Solving with C++
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">	<html>		<head>			<title>page_948</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_947.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_948</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_949.html">next page&nbsp;&gt;</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 948</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">order. The location in this algorithm that we must change is where the minimum value is determined. Instead of comparing two time cards in the list (which doesn't make any sense), we compare the <i>ID numbers</i> on the time cards. To inspect the ID number on a time card, we use the observer function </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">IDPart</font><font face="Times New Roman, Times, Serif" size="3"> provided by the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">TimeCard</font><font face="Times New Roman, Times, Serif" size="3"> class. The statement that did the comparison in the original </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">SelSort</font><font face="Times New Roman, Times, Serif" size="3"> function must be changed from</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="Courier New, Courier, Mono New, Courier, Mono" size="2">if聽(list[placeCount]聽&lt;聽list[minIndex])</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">to</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="Courier New, Courier, Mono New, Courier, Mono" size="2">if聽(list[placeCount].IDPart()聽&lt;聽list[minIndex].IDPart())</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">We must make a similar change in the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">BinSearch</font><font face="Times New Roman, Times, Serif" size="3"> function. The original version in Chapter 12 compared the search item with list components directly. Here, we cannot compare the search item (an ID number of type </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">long</font><font face="Times New Roman, Times, Serif" size="3">) with a list component (an object of type </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">TimeCard</font><font face="Times New Roman, Times, Serif" size="3">). Again, we must use the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">IDPart</font><font face="Times New Roman, Times, Serif" size="3"> observer function to inspect the ID number on a time card.</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">Below is the implementation file for the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">TimeCardList</font><font face="Times New Roman, Times, Serif" size="3"> class.</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="Courier New, Courier, Mono New, Courier, Mono" size="2">//******************************************************************<br />//聽IMPLEMENTATION聽FILE聽(tclist.cpp)<br />//聽This聽file聽implements聽the聽TimeCardList聽class聽member聽functions.<br />//聽List聽representation:聽an聽array聽of聽TimeCard聽objects聽and聽an<br />//聽integer聽variable聽giving聽the聽current聽length聽of聽the聽list<br />//******************************************************************<br />#include聽tclist.h<br />#include聽&lt;iostream.h&gt;<br /><br />//聽Private聽members聽of聽class:<br />//聽聽聽聽TimeCard聽list[MAX_LENGTH];聽聽聽聽Array聽of聽TimeCard聽objects<br />//聽聽聽聽int聽聽聽聽聽聽length;聽聽聽聽聽聽聽聽聽聽聽聽聽聽Current聽length聽of聽list<br /><br />//******************************************************************<br /><br />TimeCardList::TimeCardList()<br /><br />//聽Default聽constructor<br /><br />//聽Postcondition:<br />//聽聽聽聽聽Each聽element聽of聽list聽array聽has聽an聽ID聽number聽of聽0<br />//聽聽聽聽聽and聽a聽time聽of聽0:0:0聽(via聽implicit聽call聽to聽each聽array<br />//聽聽聽聽聽element's聽default聽constructor)<br /></font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table></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_947.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_948</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_949.html">next page&nbsp;&gt;</a></td>			</tr>		</table>		</body>	</html>

⌨️ 快捷键说明

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