page106.html

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

HTML
39
字号
<HTML><HEAD><TITLE>__copy__ Method</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="tex2html2434" HREF="page107.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2432" HREF="page97.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2426" HREF="page105.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html2436" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H2><A NAME="SECTION004390000000000000000"><tt>__copy__</tt> Method</A></H2><P>The code for the <tt>__copy__</tt> methodof the <tt>LinkedList</tt> class is given in Program&nbsp;<A HREF="page106.html#proglinkedListh"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.The <tt>__copy__</tt> method is usedto create a shallow copy of a given list.<P><P><A NAME="4160">&#160;</A><A NAME="proglinkedListh">&#160;</A> <IMG WIDTH=575 HEIGHT=218 ALIGN=BOTTOM ALT="program3970" SRC="img635.gif"  ><BR><STRONG>Program:</STRONG> <tt>LinkedList</tt> class <tt>__copy__</tt> method.<BR><P><P>The <tt>__copy__</tt> method first creates a new empty <tt>LinkedList</tt> instance.Then, it traverses the elements of the given list one-by-onecalling the <tt>append</tt> method to append the itemsto the new list.<P>In Section&nbsp;<A HREF="page105.html#secfdsappend"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> the running time for the <tt>append</tt>method was determined to be <I>O</I>(1).If the resulting list has <I>n</I> elements,the <tt>append</tt> method will be called <I>n</I> times.Therefore, the running time of the <tt>__copy__</tt> method is <I>O</I>(<I>n</I>).<P><HR><A NAME="tex2html2434" HREF="page107.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2432" HREF="page97.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2426" HREF="page105.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html2436" 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 + -
显示快捷键?