page356.html
来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 47 行
HTML
47 行
<HTML><HEAD><TITLE>Implementation</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="tex2html5292" HREF="page357.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html5290" HREF="page353.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html5284" HREF="page355.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html5294" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H2><A NAME="SECTION0011220000000000000000">Implementation</A></H2><P>A binary heap is a heap-ordered complete binary treewhich is implemented using an array.In a heap the smallest key is found at the rootand since the root is always found in the first position of the array,finding the smallest key is a trivial operation in a binary heap.<P>In this section we describe the implementationof a priority queue as a binary heap.As shown in Figure <A HREF="page356.html#figclasses7"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>,we define a concrete class called <tt>BinaryHeap</tt>for this purpose.<P><P><A NAME="24269"> </A><A NAME="figclasses7"> </A> <IMG WIDTH=576 HEIGHT=413 ALIGN=BOTTOM ALT="figure24265" SRC="img1407.gif" ><BR><STRONG>Figure:</STRONG> Object class hierarchy<BR><P><P>Program <A HREF="page356.html#progbinaryHeapa"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> introduces the <tt>BinaryHeap</tt> class.The <tt>BinaryHeap</tt> class extendsthe abstract <tt>PriorityQueue</tt> classdefined in Program <A HREF="page352.html#progpriorityQueuea"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.<P><P><A NAME="24334"> </A><A NAME="progbinaryHeapa"> </A> <IMG WIDTH=575 HEIGHT=237 ALIGN=BOTTOM ALT="program24277" SRC="img1408.gif" ><BR><STRONG>Program:</STRONG> <tt>BinaryHeap</tt> class <tt>__init__</tt> and <tt>purge</tt> methods.<BR><P><BR> <HR><UL> <LI> <A NAME="tex2html5295" HREF="page357.html#SECTION0011221000000000000000">Instance Attributes</A><LI> <A NAME="tex2html5296" HREF="page358.html#SECTION0011222000000000000000"><tt>__init__</tt> and <tt>purge</tt> Methods</A></UL><HR><A NAME="tex2html5292" HREF="page357.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html5290" HREF="page353.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html5284" HREF="page355.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html5294" 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 + -
显示快捷键?