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

📄 page269.html

📁 Data Structures And Algorithms With Object-Oriented Design Patterns In Python (2003) source code and
💻 HTML
字号:
<HTML><HEAD><TITLE>Depth-First Traversal</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="tex2html4307" HREF="page270.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html4305" HREF="page268.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html4299" HREF="page268.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html4309" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION009611000000000000000">Depth-First Traversal</A></H3><P>Program&nbsp;<A HREF="page269.html#progtreeb"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> defines the <tt>depthFirstTraversal</tt> methodof the abstract <tt>Tree</tt> class.In addition to <tt>self</tt>,the traversal method takes one argument--any object that is an instance of a subsclass ofthe <tt>PrePostVisitor</tt> class defined in Program&nbsp;<A HREF="page269.html#progprePostVisitora"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.<P><P><A NAME="15833">&#160;</A><A NAME="progtreeb">&#160;</A> <IMG WIDTH=575 HEIGHT=218 ALIGN=BOTTOM ALT="program15572" SRC="img1109.gif"  ><BR><STRONG>Program:</STRONG> Abstract <tt>Tree</tt> class <tt>depthFirstTraversal</tt> method.<BR><P><P>A <tt>PrePostVisitor</tt> is a visitor with three methods,<tt>preVisit</tt>, <tt>inVisit</tt>, <tt>postVisit</tt>,and the propderty <tt>isDone</tt>.During a depth-first traversal,the <tt>preVisit</tt> and <tt>postVisit</tt>methods are each called once for every node in the tree.(The <tt>inVisit</tt> method is provided for binary treesand is discussed in Section&nbsp;<A HREF="page292.html#sectreesbintraversal"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>).<P><P><A NAME="15835">&#160;</A><A NAME="progprePostVisitora">&#160;</A> <IMG WIDTH=575 HEIGHT=294 ALIGN=BOTTOM ALT="program15590" SRC="img1110.gif"  ><BR><STRONG>Program:</STRONG> <tt>PrePostVisitor</tt> class.<BR><P><P>The depth-first traversal method first callsthe <tt>preVisit</tt> method with the object in the root node.Then, it calls recursively the <tt>depthFirstTraversal</tt> methodfor each subtree of the given node.After all the subtrees have been visited,the <tt>postVisit</tt> method is called.Assuming that the <tt>isEmpty</tt>, <tt>key</tt>, and <tt>getSubtree</tt>operations all run in constant time,the total running time of the <tt>depthFirstTraversal</tt> method is<P> <IMG WIDTH=375 HEIGHT=16 ALIGN=BOTTOM ALT="displaymath63265" SRC="img1111.gif"  ><P>where <I>n</I> is the number of nodes in the tree, <IMG WIDTH=71 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline63269" SRC="img1112.gif"  > is the running time of <tt>preVisit</tt>,and  <IMG WIDTH=78 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline63271" SRC="img1113.gif"  > is the running time of <tt>postVisit</tt>.<P><HR><A NAME="tex2html4307" HREF="page270.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html4305" HREF="page268.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html4299" HREF="page268.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html4309" 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 + -