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 (uint64_t)
 will allocate the memory for a node and, along the data and return the node.
 
std::vector< uint64_t > inorder (Node *)
 
std::vector< 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< 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< uint64_t > inorder_result
 
std::vector< uint64_t > preorder_result
 
std::vector< 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.

Member Function Documentation

◆ createNewNode()

Node * others::recursive_tree_traversals::BT::createNewNode ( 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.
116 {
117 Node *node = new Node();
118 node->data = data;
119 node->left = node->right = nullptr;
120 return node;
121}
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< uint64_t > others::recursive_tree_traversals::BT::inorder ( Node * root)
130 {
131 if (root == nullptr) { // return if the current node is empty
132 return {};
133 }
134
135 inorder(root->left); // Traverse the left subtree
136 BT::inorder_result.push_back(
137 root->data); // Display the data part of the root (or current node)
138 inorder(root->right); // Traverse the right subtree
139
140 return inorder_result;
141}
T data(T... args)

◆ postorder()

std::vector< 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
170 {
171 if (root == nullptr) { // if the current node is empty
172 return {};
173 }
174
175 postorder(root->left); // Traverse the left subtree
176 postorder(root->right); // Traverse the right subtree
177 BT::postorder_result.push_back(
178 root->data); // Display the data part of the root (or current node)
179
180 return postorder_result;
181}
std::vector< uint64_t > postorder(Node *)
postorder function that will perform the postorder traversal recursively, and return the result vecto...
Definition recursive_tree_traversal.cpp:170
Here is the call graph for this function:

◆ preorder()

std::vector< 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
150 {
151 if (root == nullptr) { // if the current node is empty
152 return {};
153 }
154
155 BT::preorder_result.push_back(
156 root->data); // Display the data part of the root (or current node)
157 preorder(root->left); // Traverse the left subtree
158 preorder(root->right); // Traverse the right subtree
159
160 return preorder_result;
161}
std::vector< uint64_t > preorder(Node *)
preorder function that will perform the preorder traversal recursively, and return the resultant vect...
Definition recursive_tree_traversal.cpp:150
Here is the call graph for this function:

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