TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
others::recursive_tree_traversals::BT Class Reference

BT used to make the entire structure of the binary tree and the functions associated with the binary tree. More...

Collaboration diagram for others::recursive_tree_traversals::BT:
[legend]

Public Member Functions

NodecreateNewNode (std::uint64_t)
 will allocate the memory for a node and, along the data and return the node.
 
std::vector< std::uint64_t > inorder (Node *)
 
std::vector< std::uint64_t > preorder (Node *)
 preorder function that will perform the preorder traversal recursively, and return the resultant vector that contain the preorder traversal of a tree.
 
std::vector< std::uint64_t > postorder (Node *)
 postorder function that will perform the postorder traversal recursively, and return the result vector that contain the postorder traversal of a tree.
 

Public Attributes

std::vector< std::uint64_t > inorder_result
 
std::vector< std::uint64_t > preorder_result
 
std::vector< std::uint64_t > postorder_result
 

Detailed Description

BT used to make the entire structure of the binary tree and the functions associated with the binary tree.

Definition at line 88 of file recursive_tree_traversal.cpp.

Member Function Documentation

◆ createNewNode()

Node * others::recursive_tree_traversals::BT::createNewNode ( std::uint64_t data)

will allocate the memory for a node and, along the data and return the node.

Parameters
datavalue that a particular node will contain.
Returns
pointer to the newly created node with assigned data.

Definition at line 118 of file recursive_tree_traversal.cpp.

118 {
119 Node *node = new Node();
120 node->data = data;
121 node->left = node->right = nullptr;
122 return node;
123}
struct node { int data; int height; struct node *left; struct node *right;} node
for std::queue
Definition avltree.cpp:13
int data[MAX]
test data

◆ inorder()

std::vector< std::uint64_t > others::recursive_tree_traversals::BT::inorder ( Node * root)

Definition at line 132 of file recursive_tree_traversal.cpp.

132 {
133 if (root == nullptr) { // return if the current node is empty
134 return {};
135 }
136
137 inorder(root->left); // Traverse the left subtree
138 BT::inorder_result.push_back(
139 root->data); // Display the data part of the root (or current node)
140 inorder(root->right); // Traverse the right subtree
141
142 return inorder_result;
143}

◆ postorder()

std::vector< std::uint64_t > others::recursive_tree_traversals::BT::postorder ( Node * root)

postorder function that will perform the postorder traversal recursively, and return the result vector that contain the postorder traversal of a tree.

Parameters
roothead/root node of a tree
Returns
result that is containing the postorder traversal of a tree

Definition at line 172 of file recursive_tree_traversal.cpp.

172 {
173 if (root == nullptr) { // if the current node is empty
174 return {};
175 }
176
177 postorder(root->left); // Traverse the left subtree
178 postorder(root->right); // Traverse the right subtree
179 BT::postorder_result.push_back(
180 root->data); // Display the data part of the root (or current node)
181
182 return postorder_result;
183}
std::vector< std::uint64_t > postorder(Node *)
postorder function that will perform the postorder traversal recursively, and return the result vecto...

◆ preorder()

std::vector< std::uint64_t > others::recursive_tree_traversals::BT::preorder ( Node * root)

preorder function that will perform the preorder traversal recursively, and return the resultant vector that contain the preorder traversal of a tree.

Parameters
roothead/root node of a tree
Returns
result that is containing the preorder traversal of a tree

Definition at line 152 of file recursive_tree_traversal.cpp.

152 {
153 if (root == nullptr) { // if the current node is empty
154 return {};
155 }
156
157 BT::preorder_result.push_back(
158 root->data); // Display the data part of the root (or current node)
159 preorder(root->left); // Traverse the left subtree
160 preorder(root->right); // Traverse the right subtree
161
162 return preorder_result;
163}
std::vector< std::uint64_t > preorder(Node *)
preorder function that will perform the preorder traversal recursively, and return the resultant vect...

Member Data Documentation

◆ inorder_result

std::vector<std::uint64_t> others::recursive_tree_traversals::BT::inorder_result

Definition at line 91 of file recursive_tree_traversal.cpp.

◆ postorder_result

std::vector<std::uint64_t> others::recursive_tree_traversals::BT::postorder_result

Definition at line 95 of file recursive_tree_traversal.cpp.

◆ preorder_result

std::vector<std::uint64_t> others::recursive_tree_traversals::BT::preorder_result

Definition at line 93 of file recursive_tree_traversal.cpp.


The documentation for this class was generated from the following file: