#include <iostream>
#include <vector>
using std::endl;
using std::vector;
using std::cin;
using std::cout;
struct treeNode
{
int value;
treeNode*left;
treeNode*right;
};
void Path(treeNode * root ,int exceptSum,int ¤tSum,vector<int>&path,bool &isFind)
{
if(root!=NULL)
{
currentSum+=root->value;
path.push_back(root->value);
if(root->left==NULL&&root->right==NULL&¤tSum==exceptSum)
{
for(vector<int>::size_type i =0;i!=path.size();i++)
{
isFind=true;
cout<<path[i]<<" ";
}
}
Path(root->left,exceptSum,currentSum,path,isFind);
Path(root->right,exceptSum,currentSum,path,isFind);
currentSum-=root->value;
path.pop_back();
}
}
void findPath(treeNode* root,int exceptSum)
{
if(root==NULL)
{
cout<<"tree is
二叉树中和为某一值的路径
最新推荐文章于 2022-08-13 10:08:01 发布