page279.html
来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 39 行
HTML
39 行
<HTML><HEAD><TITLE>getKey and GetSubtree Methods</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="tex2html4419" HREF="page280.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html4417" HREF="page276.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html4411" HREF="page278.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html4421" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION009633000000000000000"><tt>getKey</tt> and <tt>GetSubtree</tt> Methods</A></H3><P>Program <A HREF="page279.html#proggeneralTreeb"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> defines the various <tt>GeneralTree</tt> classmethods for manipulating general trees.The <tt>getKey</tt> method returnsthe object contained by the root node of the tree.Clearly, its running time is <I>O</I>(1).<P><P><A NAME="16091"> </A><A NAME="proggeneralTreeb"> </A> <IMG WIDTH=575 HEIGHT=428 ALIGN=BOTTOM ALT="program16023" SRC="img1122.gif" ><BR><STRONG>Program:</STRONG> <tt>GeneralTree</tt> class <tt>getKey</tt>, <tt>getSubtree</tt>, <tt>attachSubtree</tt> and <tt>detachSubtree</tt> methods.<BR><P><P>The <tt>getSubtree</tt> method takes as its argument an <tt>int</tt>, <tt>i</tt>,which must be between 0 and <IMG WIDTH=82 HEIGHT=23 ALIGN=MIDDLE ALT="tex2html_wrap_inline63293" SRC="img1123.gif" >,where <tt>_degree</tt> is the degree of the root node of the tree.It returns the <IMG WIDTH=19 HEIGHT=14 ALIGN=BOTTOM ALT="tex2html_wrap_inline63295" SRC="img1124.gif" > subtree of the given tree.The <tt>getSubtree</tt> method simply takes <tt>i</tt> steps down the linked listand returns the appropriate subtree.Assuming that <tt>i</tt> is valid,the worst case running time for <tt>getSubtree</tt> is <I>O</I>(<I>d</I>),where <IMG WIDTH=80 HEIGHT=23 ALIGN=MIDDLE ALT="tex2html_wrap_inline63299" SRC="img1125.gif" > is the degree of the root node of the tree.<P><HR><A NAME="tex2html4419" HREF="page280.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html4417" HREF="page276.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html4411" HREF="page278.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html4421" 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 + -
显示快捷键?