-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsum_root_to_leaf.h
More file actions
32 lines (27 loc) · 1.08 KB
/
sum_root_to_leaf.h
File metadata and controls
32 lines (27 loc) · 1.08 KB
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
#ifndef CPP_ALGORITHM_SUM_ROOT_TO_LEAF_H
#define CPP_ALGORITHM_SUM_ROOT_TO_LEAF_H
#include "binary_tree.h"
namespace TreeSumRootToLeaf
{
/**
* \brief Sum of all root-to-leaf paths.
* \param tree the root of the tree
* \return the sum of all root-to-leaf paths
*/
auto SumRootToLeafDecimal(const BinaryTree::Node<int>* tree) -> int;
/**
* \brief Sum of all binary numbers represented by root-to-leaf paths.
* \param tree the root of the tree
* \return the sum of binary numbers represented by root-to-leaf paths
*/
auto SumRootToLeafBinary(const BinaryTree::Node<int>* tree) -> int;
/**
* \brief Whether the tree has a root-leaf path equal to the given sum.
* \details Determine if the given sum equals the sum of the keys in the path.
* \param tree the root of the tree
* \param partial_sum the partial sum of the keys in the path
* \return true if the tree has a root-leaf path equal to the given sum, false otherwise
*/
auto HasKeySum(const BinaryTree::Node<int>* tree, int partial_sum) -> bool;
}
#endif