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

📄 page_1051.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_1051</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_1050.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_1051</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_1052.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 1051</font></td></tr></table><table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td rowspan="5"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="96" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></td>  <td colspan="3" height="12"></td>  <td rowspan="5"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="96" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></td></tr><tr><td colspan="3" height="2"><table cellpadding="0" cellspacing="0" border="0"><tr><td></td></tr></table></td></tr><tr><td></td>  <td><font face="Times New Roman, Times, Serif" size="2">Dynamic Data Structure A data structure that can expand and contract during execution.</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="96" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></td>  <td colspan="3" height="12"></td>  <td rowspan="5"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="96" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></td></tr><tr><td colspan="3"></td></tr><tr><td></td>  <td><font face="Times New Roman, Times, Serif" size="2">Dynamic Linked List A linked list composed of dynamically allocated nodes that are linked together by pointers.</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" width="100%"><tr><td rowspan="5"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="96" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></td>  <td colspan="3" height="12"></td>  <td rowspan="5"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="96" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></td></tr><tr><td colspan="3"></td></tr><tr><td></td>  <td><font face="Times New Roman, Times, Serif" size="2">External (Head) Pointer A pointer variable that points to the first node in a dynamic linked list.</font></td><td></td></tr><tr><td colspan="3" height="2"><table cellpadding="0" cellspacing="0" border="0"><tr><td></td></tr></table></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 create a dynamic linked list, we begin by allocating the first node and saving the pointer to it in the external pointer. We then allocate a second node and store the pointer to it into the link member of the first node. We continue this process-allocating a new node and storing the pointer to it into the link member of the previous node-until we have finished adding nodes to 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">Let's look at how we can use C++ pointer variables to create a dynamic linked list of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">float</font><font face="Times New Roman, Times, Serif" size="3"> values. We begin with the declarations</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">typedef聽float聽ComponentType;<br /><br />struct聽NodeType<br />{<br />聽聽聽聽ComponentType聽component;<br />聽聽聽聽NodeType*聽聽聽聽聽link;<br />};<br />typedef聽NodeType*聽NodePtr;<br /><br />NodePtr聽head;聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽//聽External聽pointer聽to聽list<br />NodePtr聽currPtr;聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽//聽Pointer聽to聽current聽node<br />NodePtr聽newNodePtr;聽聽聽聽聽聽聽聽聽聽聽聽//聽Pointer聽to聽newest聽node</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 order of these declarations is important. The Typedef for </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">NodePtr</font><font face="Times New Roman, Times, Serif" size="3"> refers to the identifier </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">NodeType</font><font face="Times New Roman, Times, Serif" size="3">, so the declaration of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">NodeType</font><font face="Times New Roman, Times, Serif" size="3"> must come first. (Remember that C++ requires every identifier to be declared before it is used.) Within the declaration of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">NodeType</font><font face="Times New Roman, Times, Serif" size="3">, we would like to declare </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">link</font><font face="Times New Roman, Times, Serif" size="3"> to be of type </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">NodePtr</font><font face="Times New Roman, Times, Serif" size="3">, but we can't because the identifier </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">NodePtr</font><font face="Times New Roman, Times, Serif" size="3"> hasn't been declared yet. However, C++ allows <i>forward</i> (or <i>incomplete) declarations</i> of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">structs</font><font face="Times New Roman, Times, Serif" size="3">, classes, and unions:</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">typedef聽float聽ComponentType;<br /><br />struct聽NodeType;聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽//聽Forward聽(incomplete)聽declaration<br />typedef聽NodeType*聽NodePtr;</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_1050.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_1051</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_1052.html">next page&nbsp;&gt;</a></td>			</tr>		</table>		</body>	</html>

⌨️ 快捷键说明

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