📄 page376.html
字号:
<HTML><HEAD><TITLE>addTree and removeTree</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="tex2html5524" HREF="page377.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html5522" HREF="page371.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html5516" HREF="page375.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html5526" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION0011435000000000000000"><tt>addTree</tt> and <tt>removeTree</tt></A></H3><P>The <tt>addTree</tt> and <tt>removeTree</tt> methodsof the <tt>BinomialQueue</tt> class facilitate the implementation ofthe various priority queue operations.These methods are defined in Program <A HREF="page376.html#progbinomialQueueb"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.The <tt>addTree</tt> method takes a <tt>BinomialTree</tt>and appends that tree to <tt>_treeList</tt>.<tt>addTree</tt> also adjusts the <tt>_count</tt> in order to keeptrack of the number of items in the priority queue.It is assumed that the order of the tree which is addedis larger than all the others in the list and, therefore,that it belongs at the end of the list.The running time of <tt>addTree</tt> is clearly <I>O</I>(1).<P><P><A NAME="27127"> </A><A NAME="progbinomialQueueb"> </A> <IMG WIDTH=575 HEIGHT=218 ALIGN=BOTTOM ALT="program26937" SRC="img1507.gif" ><BR><STRONG>Program:</STRONG> <tt>BinomialQueue</tt> class <tt>addTree</tt> and <tt>removeTree</tt> methods.<BR><P><P>The <tt>removeTree</tt> method takes a binomial treeand removes it from the <tt>_treeList</tt>.It is assumed that the specified tree is actually in the list.<tt>removeTree</tt> also adjust the <tt>_count</tt> as required.The running time of <tt>removeTree</tt> depends on the position of thetree in the list.A binomial queue which contains exactly <I>n</I> items altogetherhas at most <IMG WIDTH=86 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline66325" SRC="img1508.gif" > binomial trees.Therefore, the running time of <tt>removeTree</tt> is <IMG WIDTH=56 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline59347" SRC="img400.gif" >in the worst case.<P><HR><A NAME="tex2html5524" HREF="page377.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html5522" HREF="page371.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html5516" HREF="page375.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html5526" 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 + -