page190.html
来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 69 行
HTML
69 行
<HTML><HEAD><TITLE>Sorted Lists</TITLE></HEAD><BODY bgcolor="#FFFFFF"> <a href="../index.html" target="_top"><img src="../icons/usins.gif" alt="Logo" align=right></a><b>Data Structures and Algorithms with Object-Oriented Design Patterns in Python</b><br><A NAME="tex2html3391" HREF="page191.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html3389" HREF="page168.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html3383" HREF="page189.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html3393" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H1><A NAME="SECTION007200000000000000000">Sorted Lists</A></H1><P>The next type of searchable container that we consider is a<em>sorted list</em><A NAME=9803> </A>.A sorted list is like an ordered list:It is a searchable container that holds a sequence of objects.However, the position of an item in a sorted list is not arbitrary.The items in the sequence appear in order, say,from the smallest to the largest.Of course, for such an ordering to exist,the relation used to sort the items must be a <em>total order</em><A NAME="tex2html323" HREF="footnode.html#9950"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/foot_motif.gif"></A>.<P>Program <A HREF="page190.html#progsortedLista"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> defines the <tt>SortedList</tt> class.The abstract <tt>SortedList</tt> classextends the abstract <tt>OrderedList</tt> class definedin Program <A HREF="page169.html#progorderedLista"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.<P><P><A NAME="9951"> </A><A NAME="progsortedLista"> </A> <IMG WIDTH=575 HEIGHT=88 ALIGN=BOTTOM ALT="program9816" SRC="img800.gif" ><BR><STRONG>Program:</STRONG> Abstract <tt>SortedList</tt> class.<BR><P><P>In addition to the basic repertoire of operations supported byall searchable containers,sorted lists provide the following operations(inherited from the <tt>OrderedList</tt> class):<DL ><DT><STRONG><tt>__getitem__</tt></STRONG><DD> used to access the object at a given position in the sorted list; and <DT><STRONG><tt>findPosition</tt></STRONG><DD> used to find the position of an object in the sorted list.<P> </DL><P>Sorted lists are very similar to ordered lists.As a result, we can make use of the code for ordered listswhen implementing sorted lists.Specifically, we will consider an array-based implementation ofsorted lists that is derived from the <tt>OrderedListAsArray</tt> classdefined in Section <A HREF="page170.html#seclistslista"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>,and a linked-list implementation of sorted liststhat is derived from the <tt>OrderedListAsLinkedList</tt>class given in Section <A HREF="page179.html#seclistslistp"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.<P><BR> <HR><UL> <LI> <A NAME="tex2html3394" HREF="page191.html#SECTION007210000000000000000">Array Implementation</A><LI> <A NAME="tex2html3395" HREF="page196.html#SECTION007220000000000000000">Linked-List Implementation</A><LI> <A NAME="tex2html3396" HREF="page199.html#SECTION007230000000000000000">Performance Comparison:<tt>SortedListAsArray</tt> vs. <tt>SortedListAsList</tt></A><LI> <A NAME="tex2html3397" HREF="page200.html#SECTION007240000000000000000">Applications</A></UL><HR><A NAME="tex2html3391" HREF="page191.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html3389" HREF="page168.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html3383" HREF="page189.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html3393" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <P><ADDRESS><img src="../icons/bruno.gif" alt="Bruno" align=right><a href="../copyright.html">Copyright © 2003</a> by <a href="../signature.html">Bruno R. Preiss, P.Eng.</a> All rights reserved.</ADDRESS></BODY></HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?