page323.html

来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 49 行

HTML
49
字号
<HTML><HEAD><TITLE>adjustHeight and getHeight Methods    and balanceFactor Property</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="tex2html4917" HREF="page324.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html4915" HREF="page320.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html4911" HREF="page322.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html4919" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION0010513000000000000000"><tt>adjustHeight</tt> and <tt>getHeight</tt> Methods    and <tt>balanceFactor</tt> Property</A></H3><P>Program&nbsp;<A HREF="page323.html#progavlTreeb"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> defines the <tt>getHeight</tt> and <tt>adjustHeight</tt>methods as well as the <tt>balanceFactor</tt> propertyof the <tt>AVLTree</tt> class.The <tt>getHeight</tt> method simplyreturns the value of the <tt>_height</tt> instance attribute.The running time of this method is constant.<P><P><A NAME="19445">&#160;</A><A NAME="progavlTreeb">&#160;</A> <IMG WIDTH=575 HEIGHT=428 ALIGN=BOTTOM ALT="program19357" SRC="img1275.gif"  ><BR><STRONG>Program:</STRONG> <tt>AVLTree</tt> class <tt>adjustHeight</tt> and <tt>getHeight</tt> methods 	and <tt>balanceFactor</tt> property.<BR><P><P>The purpose of <tt>adjustHeight</tt> is to recompute the heightof a node and to update the <tt>_height</tt> instance attribute.This method must be called whenever the height of one of the subtreeschanges in order to ensure the <tt>_height</tt> instance attributeis always up to date.The <tt>adjustHeight</tt> method determines the height of a nodeby adding one to the height of the highest subtree.The running time of this method is constant.<P>The <tt>balanceFactor</tt> property invokes the <tt>getBalanceFactor</tt> methodto return the difference between the heights of the left and right subtreesof a given AVL tree.By Definition&nbsp;<A HREF="page319.html#defnsrchtreeavl"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>,the empty node is AVL balanced.Therefore, the <tt>balanceFactor</tt> is zero for an empty tree.The running time of <tt>balanceFactor</tt> is constant.<P><HR><A NAME="tex2html4917" HREF="page324.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html4915" HREF="page320.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html4911" HREF="page322.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html4919" 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 &#169; 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 + -
显示快捷键?