https://blog.csdn.net/feit2417/article/details/99544525
typedef struct treeNode
{
int m_nValue;
struct treeNode* left;
struct treeNode* right;
} tree;
bool doFindPath(tree* root, int needNum, vector<int> &path) {
path.push(root->m_nValue);
int rootVlue = root->m_nValue;
if (rootVlue == needNum) {
// g如果需要的数值和当前数组相等且是叶子结点,那么打印路径
if (root->left==NULL && root->right==NULL) {
printPath(path);
}
}
if (root->left) {
doFindPath(root->left,needNum-rootVlue,path);
}
if (root->right) {
doFindPath(root->right,needNum-rootVlue,path);
}
//递归回溯退回父节点,在路径上要删除当前节点
path.pop();
}
bool findPath(tree* root, int num) {
if (root == NULL) {
return false;
}
vector<int> path;
doFindPath(root,num,path);
}