page401.html
来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 39 行
HTML
39 行
<HTML><HEAD><TITLE>Union</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="tex2html5801" HREF="page402.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html5799" HREF="page400.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html5793" HREF="page400.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html5803" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION0012321000000000000000">Union</A></H3><P>The union operation for <tt>MultisetAsLinkedList</tt> classrequires the merging of two ordered, linked listsas shown in Program <A HREF="page401.html#progmultisetAsLinkedListb"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.We have assumed that the smallest element contained in a multisetis found at the head of the linked list and the largest is at the tail.<P><P><A NAME="28252"> </A><A NAME="progmultisetAsLinkedListb"> </A> <IMG WIDTH=575 HEIGHT=466 ALIGN=BOTTOM ALT="program28071" SRC="img1595.gif" ><BR><STRONG>Program:</STRONG> <tt>MultisetAsLinkedList</tt> class <tt>__or__</tt> method.<BR><P><P>The <tt>__or__</tt> method computes its result as follows:The main loop of the program (lines 9-15) traverses the linked listsof the two operands,in each iteration appending the smallest remaining element to the result.Once one of the lists has been exhausted,the remaining elements in the other list are simply appended to the result(lines 16-21).The total running time for the <tt>__or__</tt> method is <I>O</I>(<I>m</I>+<I>n</I>),where <IMG WIDTH=76 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline66943" SRC="img1596.gif" > and <IMG WIDTH=64 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline66945" SRC="img1597.gif" >.<P><HR><A NAME="tex2html5801" HREF="page402.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html5799" HREF="page400.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html5793" HREF="page400.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html5803" 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 + -
显示快捷键?