📄 page184.html
字号:
<HTML><HEAD><TITLE>Positions of Items in a List</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="tex2html3329" HREF="page185.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html3327" HREF="page179.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html3321" HREF="page183.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html3331" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION007125000000000000000">Positions of Items in a List</A></H3><P>Program <A HREF="page184.html#progorderedListAsLinkedListh"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> gives the definition of a the<tt>OrderedListAsLinkedList.Cursor</tt> nested class.This class extends the abstract <tt>Cursor</tt> classdefined in Program <A HREF="page169.html#progcursora"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.The purpose of this class is to record the position of an itemin an ordered list implemented as a linked list.<P><P><A NAME="9892"> </A><A NAME="progorderedListAsLinkedListh"> </A> <IMG WIDTH=575 HEIGHT=294 ALIGN=BOTTOM ALT="program9466" SRC="img756.gif" ><BR><STRONG>Program:</STRONG> <tt>OrderedListAsLinkedList.Cursor</tt> class <tt>__init__</tt> and <tt>getDatum</tt> methods.<BR><P><P>The <tt>Cursor</tt> class has two instance attributes,<tt>_list</tt> and <tt>_element</tt>.The <tt>_list</tt> instance attributerefers to an <tt>OrderedListAsLinkedList</tt> instanceand the <tt>_element</tt>refers to the linked-list element in which a given item appears.Notice that this version of <tt>Cursor</tt>is fundamentally different from the array version.In the array version, the position was specified by an offset,i.e, by an <em>ordinal number</em><A NAME=9490> </A>that shows the position of the item in the ordered sequence.In the linked-list version,the position is specified by a reference to the element of the linked listin which the item is stored.Regardless of the implementation,both kinds of position provide exactly the same functionalitybecause they both implement methods definedin the abstract <tt>Cursor</tt> class.<P>The <tt>getDatum</tt> methodof the <tt>OrderedListAsLinkedList.Cursor</tt> classis also defined in Program <A HREF="page184.html#progorderedListAsLinkedListh"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.This method dereferences the <tt>_element</tt> instance attributeto obtain the required item in the ordered list.The running time is clearly <I>O</I>(1).<P><HR><A NAME="tex2html3329" HREF="page185.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html3327" HREF="page179.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html3321" HREF="page183.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html3331" 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -