Update recursive_tree_traversal.cpp

This commit is contained in:
Lajat5
2022-01-07 00:03:43 +05:30
committed by GitHub
parent 1bed798107
commit 99f1cec8f7

View File

@@ -16,8 +16,8 @@
* we are back at n again. * we are back at n again.
* *
* In normal inorder traversal, we visit the left subtree before the right * 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 * subtree. If we visit the right subtree before visiting the left subtree, it is
*referred to as reverse inorder traversal. * referred to as reverse inorder traversal.
* *
* ### Iterative Preorder Traversal of a tree * ### Iterative Preorder Traversal of a tree
* For traversing a (non-empty) binary tree in a preorder fashion, we must do * For traversing a (non-empty) binary tree in a preorder fashion, we must do
@@ -30,8 +30,8 @@
* we are back at n again. * we are back at n again.
* *
* In normal preorder traversal, visit the left subtree before the right * 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 * subtree. If we visit the right subtree before visiting the left subtree, it is
*referred to as reverse preorder traversal. * referred to as reverse preorder traversal.
* *
* ### Iterative Postorder Traversal of a tree * ### Iterative Postorder Traversal of a tree
* For traversing a (non-empty) binary tree in a postorder fashion, we must do * For traversing a (non-empty) binary tree in a postorder fashion, we must do
@@ -44,8 +44,8 @@
* (N) Process n itself. * (N) Process n itself.
* *
* In normal postorder traversal, visit the left subtree before the right * In normal postorder traversal, visit the left subtree before the right
*subtree. If we visit the right subtree before visiting the left subtree, it is * subtree. If we visit the right subtree before visiting the left subtree, it is
*referred to as reverse postorder traversal. * referred to as reverse postorder traversal.
* *
* @author [Lajat Manekar](https://github.com/Lazeeez) * @author [Lajat Manekar](https://github.com/Lazeeez)
* *
@@ -64,8 +64,8 @@ namespace others {
/****************************************************************************** /******************************************************************************
* @namespace interpolation_search * @namespace interpolation_search
* @brief Functions for the Recursive version of Inorder, Preorder, and * @brief Functions for the Recursive version of Inorder, Preorder, and
*Postorder [Traversal of the * Postorder [Traversal of the
*Tree](https://en.wikipedia.org/wiki/Tree_traversal) algorithm implementation * Tree](https://en.wikipedia.org/wiki/Tree_traversal) algorithm implementation
*******************************************************************************/ *******************************************************************************/
namespace recursive_tree_traversals { namespace recursive_tree_traversals {
@@ -82,7 +82,7 @@ struct Node {
}; };
/****************************************************************************** /******************************************************************************
* @brief BT used to make the entire structure of the binary tree and the * @brief BT used to make the entire structure of the binary tree and the
*functions associated with the binary tree * functions associated with the binary tree
*******************************************************************************/ *******************************************************************************/
class BT { class BT {
public: public:
@@ -123,7 +123,7 @@ Node *BT::createNewNode(uint64_t data) {
/****************************************************************************** /******************************************************************************
* @brief inorder() function that will perform the inorder traversal * @brief inorder() function that will perform the inorder traversal
* recursively, and return the resultant vector that contain the inorder * recursively, and return the resultant vector that contain the inorder
*traversal of a tree. * traversal of a tree.
* @param root head/root node of a tree * @param root head/root node of a tree
* @return result that is containing the inorder traversal of a tree * @return result that is containing the inorder traversal of a tree
*******************************************************************************/ *******************************************************************************/
@@ -143,7 +143,7 @@ std::vector<uint64_t> BT::inorder(Node *root) {
/****************************************************************************** /******************************************************************************
* @brief preorder function that will perform the preorder traversal * @brief preorder function that will perform the preorder traversal
* recursively, and return the resultant vector that contain the preorder * recursively, and return the resultant vector that contain the preorder
*traversal of a tree. * traversal of a tree.
* @param root head/root node of a tree * @param root head/root node of a tree
* @return result that is containing the preorder traversal of a tree * @return result that is containing the preorder traversal of a tree
*******************************************************************************/ *******************************************************************************/
@@ -163,7 +163,7 @@ std::vector<uint64_t> BT::preorder(Node *root) {
/****************************************************************************** /******************************************************************************
* @brief postorder function that will perform the postorder traversal * @brief postorder function that will perform the postorder traversal
* recursively, and return the result vector that contain the postorder * recursively, and return the result vector that contain the postorder
*traversal of a tree. * traversal of a tree.
* @param root head/root node of a tree * @param root head/root node of a tree
* @return result that is containing the postorder traversal of a tree * @return result that is containing the postorder traversal of a tree
*******************************************************************************/ *******************************************************************************/