page366.html
来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 40 行
HTML
40 行
<HTML><HEAD><TITLE>Putting Items into a Leftist Heap</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="tex2html5404" HREF="page367.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html5402" HREF="page361.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html5396" HREF="page365.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html5406" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H2><A NAME="SECTION0011340000000000000000">Putting Items into a Leftist Heap</A></H2><P>The <tt>enqueue</tt> method of the <tt>LeftistHeap</tt> classis used to put items into the heap.<tt>enqueue</tt> is easily implemented using the <tt>merge</tt> operation.That is, to enqueue an item in a given heap,we simply create a new heap containing the one item to be enqueuedand merge it with the given heap.The algorithm to do this is shown in Program <A HREF="page366.html#progleftistHeapc"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.<P><P><A NAME="26076"> </A><A NAME="progleftistHeapc"> </A> <IMG WIDTH=575 HEIGHT=122 ALIGN=BOTTOM ALT="program25961" SRC="img1438.gif" ><BR><STRONG>Program:</STRONG> <tt>LeftistHeap</tt> class <tt>enqueue</tt> method.<BR><P><P>The expression for the running time for the <tt>enqueue</tt> operationfollows directly from that of the <tt>merge</tt> operation.That is, the time required for the <tt>enqueue</tt> operation in the worst case is<P> <IMG WIDTH=329 HEIGHT=16 ALIGN=BOTTOM ALT="displaymath65911" SRC="img1439.gif" ><P>where <I>d</I> is the null path length of the heap into which the item is enqueued.If we assume that two keys can be compared in constant time,the running time for <tt>enqueue</tt> becomes simply <IMG WIDTH=56 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline59347" SRC="img400.gif" >,where <I>n</I> is the number of nodes in the tree into which the item is enqueued.<P><HR><A NAME="tex2html5404" HREF="page367.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html5402" HREF="page361.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html5396" HREF="page365.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html5406" 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 + -
显示快捷键?