FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm-examples/cpp-algorithm/src/tree/leaf_node_list.h at main · codejsha/algorithm-examples · GitHub
codejsha
/
algorithm-examples
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
Code
Issues
0
Pull requests
0
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithm-examples
/
cpp-algorithm
/
src
/
tree
/
leaf_node_list.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (45 loc) · 1.3 KB
Breadcrumbs
algorithm-examples
/
cpp-algorithm
/
src
/
tree
/
leaf_node_list.h
Copy path
File metadata and controls
51 lines (45 loc) · 1.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#
ifndef
CPP_ALGORITHM_LEAF_NODE_LIST_H
#
define
CPP_ALGORITHM_LEAF_NODE_LIST_H
#
include
"
binary_tree.h
"
#
include
<
vector
>
namespace
LeafNodeList
{
/*
*
* \brief Create a list of leaf nodes.
* \param root the root of the tree
* \return leaf node list
*/
std::vector<BinaryTree::Node<
int
>*>
CreateLeafNodeList
(
BinaryTree::Node<
int
>* root);
}
//
----------------------------------------------------------------------------
/*
*
* \brief Add leaf nodes to the list.
* \param root the root of the tree
* \param leaf_node_list leaf node list
*/
inline
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);
}
//
----------------------------------------------------------------------------
inline
std::vector<BinaryTree::Node<
int
>*>
LeafNodeList::CreateLeafNodeList
(
BinaryTree::Node<
int
>* root)
{
auto
leaf_node_list = std::vector<BinaryTree::Node<
int
>*>{};
AddLeafNodeToList
(root, leaf_node_list);
return
leaf_node_list;
}
#
endif
Back
|
FazBrowse Home
|
New Git URL