page175.html

来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 48 行

HTML
48
字号
<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="tex2html3224" HREF="page176.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html3222" HREF="page170.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html3216" HREF="page174.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html3226" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION007115000000000000000">Positions of Items in a List</A></H3><P>As shown in Program&nbsp;<A HREF="page169.html#progcursora"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>,objects that implement the <tt>Cursor</tt> interfacecan be used to access, insert, and delete objects in an ordered list.Program&nbsp;<A HREF="page175.html#progorderedListAsArrayh"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> defines the nested classcalled <tt>OrderedListAsArray.Cursor</tt>that extends the abstract <tt>Cursor</tt> class.The idea is that instances of this classare used by the <tt>OrderedListAsArray</tt> class to representthe abstraction of a <em>position</em> in an ordered list.<P><P><A NAME="8861">&#160;</A><A NAME="progorderedListAsArrayh">&#160;</A> <IMG WIDTH=575 HEIGHT=332 ALIGN=BOTTOM ALT="program8767" SRC="img744.gif"  ><BR><STRONG>Program:</STRONG> <tt>OrderedListAsArray.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>_offset</tt>.The <tt>_list</tt> instance attribute refersto an <tt>OrderedListAsArray</tt> instanceand the <tt>_offset</tt> instance attributerecords an offset in that list's array of objects.The <tt>__init__</tt> method simply assigns the given valuesto the <tt>_list</tt> and <tt>_offset</tt> instance attributes.Program&nbsp;<A HREF="page175.html#progorderedListAsArrayh"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> also defines the <tt>getDatum</tt> methodof the <tt>Cursor</tt> class.This method returns the item in the arrayat the position record in the <tt>_offset</tt> instance attribute,provided that position is valid.The running time of the accessor is simply <I>O</I>(1).<P><HR><A NAME="tex2html3224" HREF="page176.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html3222" HREF="page170.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html3216" HREF="page174.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html3226" 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 &#169; 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 + -
显示快捷键?