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

📄 page_1086.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_1086</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_1085.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_1086</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_1087.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 1086</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">The private variable head is the external pointer to the linked list, and the private variable </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">listLength</font><font face="Times New Roman, Times, Serif" size="3"> keeps track of the current length of the 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>The class constructor, copy-constructor, and destructor:</i> These functions are essentially identical to those in the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">OrdList</font><font face="Times New Roman, Times, Serif" size="3"> class. The only significant difference is in the constructor. In addition to setting </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">head</font><font face="Times New Roman, Times, Serif" size="3"> to </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">NULL</font><font face="Times New Roman, Times, Serif" size="3">, the constructor must set </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">listLength</font><font face="Times New Roman, Times, Serif" size="3"> to zero.</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>The</i> </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">InsertTop</font><font face="Times New Roman, Times, Serif" size="3"> <i>and</i> </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">RemoveTop</font><font face="Times New Roman, Times, Serif" size="3"> <i>functions:</i> These functions are the same as </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">InsertTop</font><font face="Times New Roman, Times, Serif" size="3"> and </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">DeleteTop</font><font face="Times New Roman, Times, Serif" size="3"> in the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">OrdList</font><font face="Times New Roman, Times, Serif" size="3"> class, with the following differences. After inserting a new node, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">InsertTop</font><font face="Times New Roman, Times, Serif" size="3"> must increment </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">listLength;</font><font face="Times New Roman, Times, Serif" size="3"> and after deleting a node, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">RemoveTop</font><font face="Times New Roman, Times, Serif" size="3"> must decrement </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">listLength</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"><i>The Length function:</i> Because the private variable </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">listLength</font><font face="Times New Roman, Times, Serif" size="3"> always indicates the current length of the list, no looping and counting are required. The function body is a single statement:</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">return聽listLength;</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>The</i> </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">CardAt</font><font face="Times New Roman, Times, Serif" size="3"> <i> function:</i> To access the card at position <i>n</i> in the pile, we must start at the front of the list and sequence our way through the first <i>n</i> - 1 nodes. When we get to the desired node, we return the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">card</font><font face="Times New Roman, Times, Serif" size="3"> member of the node as the function return value.</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">CardAt聽(In:聽n)</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="336" 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聽currPtr聽=聽head<br />FOR聽count聽going聽from聽1聽through聽n聽-1<br />聽聽Set聽currPtr聽=聽link聽member聽of聽</font><font face="Symbol" size="2">*</font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">currPtr<br />Return聽card聽member聽of聽</font><font face="Symbol" size="2">*</font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">currPtr</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">Here is the implementation file containing the definitions of the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">CardPile</font><font face="Times New Roman, Times, Serif" size="3"> member functions:</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聽(cardpile.cpp)<br />//聽This聽file聽implements聽the聽CardPile聽class聽member聽functions<br />//聽List聽representation:聽a聽linked聽list聽of聽dynamic聽nodes<br />//******************************************************************<br />#include聽cardpile.h<br />#include聽&lt;stddef.h&gt;聽聽聽聽聽//聽For聽NULL</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_1085.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_1086</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_1087.html">next page&nbsp;&gt;</a></td>			</tr>		</table>		</body>	</html>

⌨️ 快捷键说明

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