mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-03-24 05:42:59 +08:00
Documentation for 0fea073413
This commit is contained in:
@@ -155,17 +155,17 @@ Functions</h2></td></tr>
|
||||
</table>
|
||||
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
||||
<div class="textblock"><p >Recursive version of Inorder, Preorder, and Postorder [Traversal of the Tree] (<a href="https://en.wikipedia.org/wiki/Tree_traversal">https://en.wikipedia.org/wiki/Tree_traversal</a>) </p>
|
||||
<h3><a class="anchor" id="autotoc_md96"></a>
|
||||
<h3><a class="anchor" id="autotoc_md97"></a>
|
||||
Iterative Inorder Traversal of a tree</h3>
|
||||
<p >For traversing a (non-empty) binary tree in an inorder fashion, we must do these three things for every node n starting from the tree’s root:</p>
|
||||
<p >(L) Recursively traverse its left subtree. When this step is finished, we are back at n again. (N) Process n itself. (R) Recursively traverse its right subtree. When this step is finished, we are back at n again.</p>
|
||||
<p >In normal inorder traversal, we visit the left subtree before the right subtree. If we visit the right subtree before visiting the left subtree, it is referred to as reverse inorder traversal.</p>
|
||||
<h3><a class="anchor" id="autotoc_md97"></a>
|
||||
<h3><a class="anchor" id="autotoc_md98"></a>
|
||||
Iterative Preorder Traversal of a tree</h3>
|
||||
<p >For traversing a (non-empty) binary tree in a preorder fashion, we must do these three things for every node n starting from the tree’s root:</p>
|
||||
<p >(N) Process n itself. (L) Recursively traverse its left subtree. When this step is finished, we are back at n again. (R) Recursively traverse its right subtree. When this step is finished, we are back at n again.</p>
|
||||
<p >In normal preorder traversal, visit the left subtree before the right subtree. If we visit the right subtree before visiting the left subtree, it is referred to as reverse preorder traversal.</p>
|
||||
<h3><a class="anchor" id="autotoc_md98"></a>
|
||||
<h3><a class="anchor" id="autotoc_md99"></a>
|
||||
Iterative Postorder Traversal of a tree</h3>
|
||||
<p >For traversing a (non-empty) binary tree in a postorder fashion, we must do these three things for every node n starting from the tree’s root:</p>
|
||||
<p >(L) Recursively traverse its left subtree. When this step is finished, we are back at n again. (R) Recursively traverse its right subtree. When this step is finished, we are back at n again. (N) Process n itself.</p>
|
||||
|
||||
Reference in New Issue
Block a user