page267.html
来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 79 行
HTML
79 行
<HTML><HEAD><TITLE>Implementing Trees</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="tex2html4273" HREF="page268.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html4271" HREF="page251.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html4265" HREF="page266.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html4275" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H1><A NAME="SECTION009600000000000000000">Implementing Trees</A></H1><A NAME="sectreesimpltree"> </A><P>In this section we consider the implementation of treesincluding general trees, <I>N</I>-ary trees, and binary trees.The implementations presented have been developed in the contextof the abstract data type framework presented in Chapter <A HREF="page111.html#chapadts"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.That is, the various types of trees are viewedas classes of <em>containers</em>as shown in Figure <A HREF="page267.html#figclasses5"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.<P><P><A NAME="15500"> </A><A NAME="figclasses5"> </A> <IMG WIDTH=576 HEIGHT=326 ALIGN=BOTTOM ALT="figure15496" SRC="img1107.gif" ><BR><STRONG>Figure:</STRONG> Object class hierarchy<BR><P><P>Program <A HREF="page267.html#progtreea"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> introduces the <tt>Tree</tt> class.The abstract <tt>Tree</tt> class extendsthe abstract <tt>Container</tt> class introduced in Program <A HREF="page119.html#progcontainera"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.<P><P><A NAME="15819"> </A><A NAME="progtreea"> </A> <IMG WIDTH=575 HEIGHT=676 ALIGN=BOTTOM ALT="program15508" SRC="img1108.gif" ><BR><STRONG>Program:</STRONG> Abstract <tt>Tree</tt> class.<BR><P><P>The abstract <tt>Tree</tt> class adds the following operationsto those inherited from the <tt>Container</tt> class:<DL ><DT><STRONG><tt>key</tt></STRONG><DD> This property accesses the object contained in the root node of a tree. <DT><STRONG><tt>getSubtree</tt></STRONG><DD> This method returns the <IMG WIDTH=17 HEIGHT=14 ALIGN=BOTTOM ALT="tex2html_wrap_inline57847" SRC="img77.gif" > subtree of the given tree. <DT><STRONG><tt>isEmpty</tt></STRONG><DD> This <tt>bool</tt>-valued property is <tt>true</tt> if the root of the tree is an empty tree, i.e., an external node. <DT><STRONG><tt>isLeaf</tt></STRONG><DD> This <tt>bool</tt>-valued property is <tt>true</tt> if the root of the tree is a leaf node. <DT><STRONG><tt>degree</tt></STRONG><DD> This property accesses the degree of the root node of the tree. By definition, the degree of an external node is zero. <DT><STRONG><tt>height</tt></STRONG><DD> This property accesses the height of the tree. By definition, the height of an empty tree is -1. <DT><STRONG><tt>depthFirstTraversal</tt> and <tt>breadthFirstTraversal</tt></STRONG><DD><P> </DL><BR> <HR><UL> <LI> <A NAME="tex2html4276" HREF="page268.html#SECTION009610000000000000000">Tree Traversals</A><LI> <A NAME="tex2html4277" HREF="page273.html#SECTION009620000000000000000">Tree Iterators</A><LI> <A NAME="tex2html4278" HREF="page276.html#SECTION009630000000000000000">General Trees</A><LI> <A NAME="tex2html4279" HREF="page281.html#SECTION009640000000000000000"><I>N</I>-ary Trees</A><LI> <A NAME="tex2html4280" HREF="page287.html#SECTION009650000000000000000">Binary Trees</A><LI> <A NAME="tex2html4281" HREF="page292.html#SECTION009660000000000000000">Binary Tree Traversals</A><LI> <A NAME="tex2html4282" HREF="page293.html#SECTION009670000000000000000">Comparing Trees</A><LI> <A NAME="tex2html4283" HREF="page294.html#SECTION009680000000000000000">Applications</A></UL><HR><A NAME="tex2html4273" HREF="page268.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html4271" HREF="page251.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html4265" HREF="page266.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html4275" 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 + -
显示快捷键?