#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
using namespace std;
vector<int> result;
struct Node {
Node(int i = 0, Node *pl = NULL, Node *pr = NULL) : data(i), left(pl), right(pr) {}
int data;
Node *left;
Node *right;
};
Node* Construct()
{
Node *node4 = new Node(7);
Node *node3 = new Node(4);
Node *node2 = new Node(12);
Node *node1 = new Node(5, node3, node4);
Node *root = new Node(10, node1, node2);
return root;
}
void print()
{
copy(result.begin(), result.end(), ostream_iterator<int>(cout, " "));
cout << endl;
}
void PrintSum(Node *root, int sum)
{
if(root == NULL)
return;
result.push_back(root->data);
if(root->left == NULL && root->right == NULL && root->data == sum) {
print();
}
PrintSum(root->left, sum - root->data);
PrintSum(root->right, sum - root->data);
result.pop_back();
}
void main()
{
Node *root = Construct();
PrintSum(root, 22);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有