Algorithms_in_C++ 1.0.0
Set of 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_tinorder (Node *)
 
std::vector< std::uint64_tpreorder (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_tpostorder (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_tinorder_result
 
std::vector< std::uint64_tpreorder_result
 
std::vector< std::uint64_tpostorder_result
 

Detailed Description

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

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.
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
Definition hash_search.cpp:24
Definition linkedlist_implentation_usingarray.cpp:14
Definition binary_search_tree.cpp:11

◆ inorder()

std::vector< std::uint64_t > others::recursive_tree_traversals::BT::inorder ( Node * root)
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
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...
Definition recursive_tree_traversal.cpp:172
Here is the call graph for this function:

◆ 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
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...
Definition recursive_tree_traversal.cpp:152
Here is the call graph for this function:

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