page195.html

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

HTML
45
字号
<HTML><HEAD><TITLE>Removing Items from 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="tex2html3452" HREF="page196.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html3450" HREF="page191.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html3446" HREF="page194.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html3454" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION007214000000000000000">Removing Items from a List</A></H3><P>The purpose of the <tt>withdraw</tt> method is to removean item from the sorted list.Program&nbsp;<A HREF="page195.html#progsortedListAsArraye"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> defines the <tt>withdraw</tt>method which takes an object and removes it from the sorted list.<P><P><A NAME="10459">&#160;</A><A NAME="progsortedListAsArraye">&#160;</A> <IMG WIDTH=575 HEIGHT=313 ALIGN=BOTTOM ALT="program10196" SRC="img812.gif"  ><BR><STRONG>Program:</STRONG> <tt>SortedListAsArray</tt> class <tt>withdraw</tt> method.<BR><P><P>The <tt>withdraw</tt> method makes use of <tt>findOffset</tt>to determine the array index of the item to be removed.Removing an object from position <I>i</I> of an ordered list which is stored in an arrayrequires that all of the objects at positions<I>i</I>+1, <I>i</I>+2, ...,  <IMG WIDTH=74 HEIGHT=20 ALIGN=MIDDLE ALT="tex2html_wrap_inline60683" SRC="img661.gif"  >,be moved one position to the left.The worst case is when <I>i</I>=0.In this case,  <IMG WIDTH=74 HEIGHT=20 ALIGN=MIDDLE ALT="tex2html_wrap_inline60683" SRC="img661.gif"  > items need to be moved to the left.<P>Although the <tt>withdraw</tt> method is able to makeuse of <tt>findOffset</tt> to locate the positionof the item to be removed in  <IMG WIDTH=56 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline59347" SRC="img400.gif"  > time,the total running time is dominated by the left shift,which is <I>O</I>(<I>n</I>) in the worst case.Therefore, the running time of <tt>withdraw</tt> is <I>O</I>(<I>n</I>).<P><HR><A NAME="tex2html3452" HREF="page196.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html3450" HREF="page191.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html3446" HREF="page194.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html3454" 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 + -
显示快捷键?