⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 page292.html

📁 Data Structures And Algorithms With Object-Oriented Design Patterns In Python (2003) source code and
💻 HTML
字号:
<HTML><HEAD><TITLE>Binary Tree Traversals</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="tex2html4565" HREF="page293.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html4563" HREF="page267.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html4557" HREF="page291.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html4567" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H2><A NAME="SECTION009660000000000000000">Binary Tree Traversals</A></H2><A NAME="sectreesbintraversal">&#160;</A><P>Program&nbsp;<A HREF="page292.html#progbinaryTreec"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> defines the <tt>depthFirstTraversal</tt>method of the <tt>BinaryTree</tt> class.This method supports all three tree traversal methods--preorder, inorder, and postorder.The implementation follows directly from the definitionsgiven in Section&nbsp;<A HREF="page258.html#sectreestraversals"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.The traversal is implemented using recursion.That is, the method calls itself recursivelyto visit the subtrees of the given node.Note that the recursion terminates properly when an empty tree is encounteredsince the method does nothing in that case.<P><P><A NAME="16708">&#160;</A><A NAME="progbinaryTreec">&#160;</A> <IMG WIDTH=575 HEIGHT=237 ALIGN=BOTTOM ALT="program16561" SRC="img1134.gif"  ><BR><STRONG>Program:</STRONG> <tt>BinaryTree</tt> class <tt>DepthFirstTraversal</tt> method.<BR><P><P>In addition to <tt>self</tt>,the traversal method takes as its argumentany instance of a class that extends the  <tt>prePostVisitor</tt> interfacedefined in Program&nbsp;<A HREF="page269.html#progprePostVisitora"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.As each node is ``visited'' during the course of the traversal,the <tt>preVisit</tt>, <tt>inVisit</tt>, and <tt>postVisit</tt>methods of the visitor are invoked on the object contained in that node.<P><HR><A NAME="tex2html4565" HREF="page293.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html4563" HREF="page267.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html4557" HREF="page291.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html4567" 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -