page259.html

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

HTML
41
字号
<HTML><HEAD><TITLE>Preorder 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="tex2html4186" HREF="page260.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html4184" HREF="page258.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html4178" HREF="page258.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html4188" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION009401000000000000000">Preorder Traversal</A></H3><P>The first depth-first traversal methodwe consider is called<em>preorder traversal</em><A NAME=15245>&#160;</A><A NAME=15246>&#160;</A>.Preorder traversal is defined recursively as follows.To do a preorder traversal of a general tree:<OL><LI> Visit the root first; and then<LI> do a preorder traversal each of the subtrees of the root	one-by-one in the order given.</OL>Preorder traversal gets its name from the fact that it visits the root first.In the case of a binary tree,the algorithm becomes:<OL><LI> Visit the root first; and then<LI> traverse the left subtree; and then<LI> traverse the right subtree.</OL>For example, a preorder traversal of the tree shown in Figure&nbsp;<A HREF="page258.html#figtree5"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>visits the nodes in the following order:<P> <IMG WIDTH=333 HEIGHT=15 ALIGN=BOTTOM ALT="displaymath63209" SRC="img1097.gif"  ><P>Notice that the preorder traversal visits the nodes of the treein precisely the same order in which they are writtenin Equation&nbsp;<A HREF="page258.html#eqntreest"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.A preorder traversal is often done when it is necessaryto print a textual representation of a tree.<P><HR><A NAME="tex2html4186" HREF="page260.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html4184" HREF="page258.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html4178" HREF="page258.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html4188" 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 + -
显示快捷键?