497-499.html
来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 187 行
HTML
187 行
<HTML>
<HEAD>
<TITLE>Linux Unleashed, Third Edition:Programming in C++</TITLE>
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!--ISBN=0672313723//-->
<!--TITLE=Linux Unleashed, Third Edition//-->
<!--AUTHOR=Tim Parker//-->
<!--PUBLISHER=Macmillan Computer Publishing//-->
<!--IMPRINT=Sams//-->
<!--CHAPTER=27//-->
<!--PAGES=497-499//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="494-497.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="499-500.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading17"></A><FONT COLOR="#000077">Linked Lists</FONT></H4>
<P>The GNU C++ library supports two kinds of linked lists: single linked lists implemented by the <TT>SLList</TT> class, and doubly linked lists implemented by the <TT>DLList</TT> class. Both of these types of lists support all the standard linked list operations. A summary of the operations that these classes support is shown in Table 27.5.</P>
<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 27.5.</B> List operators.
<TR>
<TH COLSPAN="2"><HR>
<TR>
<TH WIDTH="40%" ALIGN="LEFT">Operator
<TH WIDTH="60%" ALIGN="LEFT">Description
<TR>
<TH COLSPAN="2"><HR>
<TR>
<TD><TT>list.empty()</TT>
<TD>Returns <TT>TRUE</TT> if <TT>list</TT> is empty
<TR>
<TD><TT>list.length()</TT>
<TD>Returns the number of elements in <TT>list</TT>
<TR>
<TD><TT>list.prepend(a)</TT>
<TD>Places <TT>a</TT> at the front of <TT>list</TT>
<TR>
<TD><TT>list.append(a)</TT>
<TD>Places <TT>a</TT> at the end of <TT>list</TT>
<TR>
<TD VALIGN="TOP"><TT>list.join(list2)</TT>
<TD>Appends <TT>list2</TT> to <TT>list</TT>, destroying <TT>list2</TT> in the process
<TR>
<TD VALIGN="TOP"><TT>a = list.front()</TT>
<TD>Returns a pointer to the element that is stored at the head of the list
<TR>
<TD VALIGN="TOP"><TT>a = list.rear()</TT>
<TD>Returns a pointer to the element that is stored at the end of the list
<TR>
<TD VALIGN="TOP"><TT>a = list.remove_front()</TT>
<TD>Deletes and returns the element that is stored at the front of the list
<TR>
<TD><TT>list.del_front()</TT>
<TD>Deletes the first element without returning it
<TR>
<TD><TT>list.clear()</TT>
<TD>Deletes all items from <TT>list</TT>
<TR>
<TD><TT>list.ins_after(i, a)</TT>
<TD>Inserts <TT>a</TT> after position <TT>i</TT> in the list
<TR>
<TD><TT>list.del_after(i)</TT>
<TD>Deletes the element following position <TT>i</TT> in the list
<TR>
<TD COLSPAN="2"><HR>
</TABLE>
<P>Doubly linked lists also support the operations listed in Table 27.6.
</P>
<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 27.6.</B> Doubly linked list operators.
<TR>
<TH COLSPAN="2"><HR>
<TR>
<TH WIDTH="40%" ALIGN="LEFT">Operator
<TH WIDTH="60%" ALIGN="LEFT">Description
<TR>
<TH COLSPAN="2"><HR>
<TR>
<TD VALIGN="TOP"><TT>a = list.remove_rear()</TT>
<TD>Deletes and returns the element stored at the end of the list
<TR>
<TD><TT>list.del_real()</TT>
<TD>Deletes the last element, without returning it
<TR>
<TD><TT>list.ins_before(i, a)</TT>
<TD>Inserts <TT>a</TT> before position <TT>i</TT> in the list
<TR>
<TD VALIGN="TOP"><TT>list.del(i, dir)</TT>
<TD>Deletes the element at the current position and then moves forward one position if <TT>dir</TT> is positive and backward one position if <TT>dir</TT> is 0 or negative
<TR>
<TD COLSPAN="2"><HR>
</TABLE>
<H4 ALIGN="LEFT"><A NAME="Heading18"></A><FONT COLOR="#000077">Plex Classes</FONT></H4>
<P><TT>Plex</TT> classes are classes that behave like arrays but are much more powerful. <TT>Plex</TT> classes have the following properties:</P>
<DL>
<DD><B>•</B> They have arbitrary upper and lower index bounds.
<DD><B>•</B> They can dynamically expand in both the lower and upper bound directions.
<DD><B>•</B> Elements may be accessed by indices. Unlike typical arrays, bounds checking is performed at runtime.
<DD><B>•</B> Only elements that have been specifically initialized or added can be accessed.
</DL>
<P>Four different types of <TT>Plex</TT>es are defined: the <TT>FPlex</TT>, the <TT>XPlex</TT>, the <TT>RPlex</TT>, and the <TT>MPlex</TT>. The <TT>FPlex</TT> is a <TT>Plex</TT> that can grow or shrink only within declared bounds. An <TT>XPlex</TT> can dynamically grow in any direction without any restrictions. An <TT>RPlex</TT> is almost identical to an <TT>XPlex</TT>, but it has better indexing capabilities. Finally, the <TT>MPlex</TT> is the same as an <TT>RPlex</TT> except that it allows elements to be logically deleted and restored.</P>
<P>Table 27.7 lists some of the operations that are valid on all four of the <TT>Plex</TT>es.</P>
<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 27.7.</B> Operations defined for <TT>Plex</TT>es.
<TR>
<TH COLSPAN="2"><HR>
<TR>
<TH WIDTH="40%" ALIGN="LEFT">Operation
<TH WIDTH="60%" ALIGN="LEFT">Description
<TR>
<TH COLSPAN="2"><HR>
<TR>
<TD><TT>Plex b(a)</TT>
<TD>Assigns a copy of <TT>Plex a</TT> to <TT>Plex b</TT>
<TR>
<TD><TT>b = a</TT>
<TD>Copies <TT>Plex a</TT> into <TT>b
<TR>
<TD><TT>a.length()</TT>
<TD>Returns the number of elements in <TT>a</TT>
<TR>
<TD><TT>a.empty()</TT>
<TD>Returns <TT>TRUE</TT> if <TT>a</TT> has no elements
<TR>
<TD><TT>a.full()</TT>
<TD>Returns <TT>TRUE</TT> if <TT>a</TT> is full
<TR>
<TD><TT>a.clear()</TT>
<TD>Removes all the elements from <TT>a</TT>
<TR>
<TD><TT>a.append(b)</TT>
<TD>Appends <TT>Plex b</TT> to the high part of <TT>a</TT>
<TR>
<TD><TT>a.prepend(b)</TT>
<TD>Prepends <TT>Plex b</TT> to the low part of <TT>a</TT>
<TR>
<TD><TT>a.fill(z)</TT>
<TD>Sets all elements of <TT>a</TT> equal to <TT>z</TT>
<TR>
<TD><TT>a.valid(i)</TT>
<TD>Returns <TT>TRUE</TT> if <TT>i</TT> is a valid index into <TT>a</TT>
<TR>
<TD VALIGN="TOP"><TT>a.low_element()</TT>
<TD>Returns a pointer to the element in the lowest position in <TT>a</TT>
<TR>
<TD VALIGN="TOP"><TT>a.high_element()</TT>
<TD>Returns a pointer to the element in the highest position in <TT>a</TT>
<TR>
<TD COLSPAN="2"><HR>
</TABLE>
<P><TT>Plex</TT>es are a very useful class on which many of the other classes in the GNU C++ class library are based. Some of the <TT>Stack</TT>, <TT>Queue</TT>, and <TT>Linked</TT> list types are built on top of the <TT>Plex</TT> class.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="494-497.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="499-500.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?