page178.html
来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 50 行
HTML
50 行
<HTML><HEAD><TITLE>Removing Arbitrary Items by Position</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="tex2html3255" HREF="page179.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html3253" HREF="page170.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html3249" HREF="page177.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html3257" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION007118000000000000000">Removing Arbitrary Items by Position</A></H3><P>The final method of the <tt>OrderedListAsArray.Cursor</tt> class that we willconsider is the <tt>withdraw</tt> method.The desired effect of this method is to remove from the ordered listthe item at the position specified by the cursor.<P>Figure <A HREF="page178.html#figlists2"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> shows the way in which to deletean item from an ordered list which implemented with an array.All of the items remaining in the list to the right of the deleted itemneed to be shifted to the left in the array by one position.<P><P><A NAME="9335"> </A><A NAME="figlists2"> </A> <IMG WIDTH=575 HEIGHT=284 ALIGN=BOTTOM ALT="figure9077" SRC="img749.gif" ><BR><STRONG>Figure:</STRONG> Withdrawing an item from an ordered list implemented as an array.<BR><P><P>Program <A HREF="page178.html#progorderedListAsArrayg"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> gives the implementationof the <tt>withdraw</tt> method.After checking the validity of the position,all of the items following the item to be withdraw are movedone position to the left in the array.<P><P><A NAME="9876"> </A><A NAME="progorderedListAsArrayg"> </A> <IMG WIDTH=575 HEIGHT=409 ALIGN=BOTTOM ALT="program9340" SRC="img750.gif" ><BR><STRONG>Program:</STRONG> <tt>OrderedListAsArray.Cursor</tt> class <tt>withdraw</tt> method.<BR><P><P>The running time of the <tt>withdraw</tt> methoddepends on the position in the array of the item being deletedand on the number of items in the ordered lists.In the worst case, the item to be deleted is in the first position.In this case, the work required to move the remaining items left is <I>O</I>(<I>n</I>),where <IMG WIDTH=78 HEIGHT=9 ALIGN=BOTTOM ALT="tex2html_wrap_inline61037" SRC="img743.gif" >.<P><HR><A NAME="tex2html3255" HREF="page179.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html3253" HREF="page170.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html3249" HREF="page177.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html3257" 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 + -
显示快捷键?