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

📄 page_1116.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_1116</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_1115.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_1116</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_1117.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 1116</font></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="24" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></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">struct聽NodeType<br />{<br />聽聽聽聽int聽聽聽聽聽number;<br />聽聽聽聽NodePtr聽link;<br />};</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"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="29" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></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">and the function prototype</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"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="24" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></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">void聽Exchange(聽/*聽in聽*/聽NodePtr聽head,<br />聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽/*聽in聽*/聽int聽聽聽聽聽key聽聽);</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"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="29" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></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">implement the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Exchange</font><font face="Times New Roman, Times, Serif" size="3"> function. The function searches a linked list for the value given by </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">key</font><font face="Times New Roman, Times, Serif" size="3"> and exchanges it with the number preceding it in the list. If </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">key</font><font face="Times New Roman, Times, Serif" size="3"> is the first value in the list or if </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">key</font><font face="Times New Roman, Times, Serif" size="3"> is not found, then no exchange occurs.</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">10. Using the type declarations given in Exercise 9, write a function that reorganizes the items in a linked list so that the last item is first, the second to last is second, and so forth. (<i>Hint:</i> Use a temporary list.)</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"><i>Programming Problems</i></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">1. In the Solitaire program in this chapter, all insertions into a linked list are made using the function </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">InsertTop</font><font face="Times New Roman, Times, Serif" size="3">, and all the deletions are made using </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">RemoveTop</font><font face="Times New Roman, Times, Serif" size="3">. In some cases, this is inefficient. For example, function </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">CardDeck::Recreate</font><font face="Times New Roman, Times, Serif" size="3"> takes the cards from </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">onTable</font><font face="Times New Roman, Times, Serif" size="3"> and moves them one by one to the deck. Then the cards on </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">discardPile</font><font face="Times New Roman, Times, Serif" size="3"> are moved one by one to the deck. It would be more efficient simply to concatenate (join) the deck list and the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">onTable</font><font face="Times New Roman, Times, Serif" size="3"> list, then concatenate the resulting list and the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">discardPile</font><font face="Times New Roman, Times, Serif" size="3"> list.</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"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="29" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></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 the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">CardPile</font><font face="Times New Roman, Times, Serif" size="3"> class, add a member function whose specification is the following:</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"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="24" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></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">void聽Concat(聽/*聽inout聽*/聽CardPile&amp;聽otherList聽);<br />聽聽聽聽//聽Postcondition:<br />聽聽聽聽//聽聽聽聽聽This聽list聽and聽otherList聽are聽concatenated聽(the聽front<br />聽聽聽聽//聽聽聽聽聽of聽otherList聽is聽joined聽to聽the聽rear聽of聽this聽list)<br />聽聽聽聽//聽聽&amp;&amp;聽otherList聽is聽empty</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"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="29" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></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">Implement and test the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Concat</font><font face="Times New Roman, Times, Serif" size="3"> member function. Use it in the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">CardDeck::Recreate</font><font face="Times New Roman, Times, Serif" size="3"> function of the Solitaire program to make the program more efficient.</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">2. In Chapter 15, the BirthdayCalls program uses a </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">DateType</font><font face="Times New Roman, Times, Serif" size="3"> class to process address book information found in a file </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">friendFile</font><font face="Times New Roman, Times, Serif" size="3">. Entries in </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">friendFile</font><font face="Times New Roman, Times, Serif" size="3"> are in the form</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"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="24" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></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">John聽Arbuthnot<br />(493)聽3842938<br />1/12/1970<br /><br />Mary聽Smith<br />(123)聽1234567<br />10/12/1960</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_1115.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_1116</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_1117.html">next page&nbsp;&gt;</a></td>			</tr>		</table>		</body>	</html>

⌨️ 快捷键说明

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