📄 page401.html
字号:
<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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -