-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleaf_node_list.cpp
More file actions
28 lines (26 loc) · 789 Bytes
/
Copy pathleaf_node_list.cpp
File metadata and controls
28 lines (26 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "leaf_node_list.h"
/**
* \brief Add leaf nodes to the list.
* \param root the root of the tree
* \param leaf_node_list leaf node list
*/
void AddLeafNodeToList(BinaryTree::Node<int>* root, std::vector<BinaryTree::Node<int>*>& leaf_node_list)
{
if (root == nullptr)
{
return;
}
if (root->left == nullptr && root->right == nullptr)
{
leaf_node_list.push_back(root);
return;
}
AddLeafNodeToList(root->left, leaf_node_list);
AddLeafNodeToList(root->right, leaf_node_list);
}
auto LeafNodeList::CreateLeafNodeList(BinaryTree::Node<int>* root) -> std::vector<BinaryTree::Node<int>*>
{
auto leaf_node_list = std::vector<BinaryTree::Node<int>*>{};
AddLeafNodeToList(root, leaf_node_list);
return leaf_node_list;
}