typedef struct treeNode{
int data;
struct treeNode *pLeft;
struct treeNode *pRight;
}treeNode;
void printAllPathWithSum(treeNode *pRoot, int sum, list<treeNode *>&path, int ¤tSum){
if(pRoot == NULL){
return;
}
currentSum += pRoot->data;
path.push_back(pRoot);
if(currentSum == sum && pRoot->pLeft == NULL && pRoot->pRight == NULL){
list<treeNode *>::iterator iter = path.begin();
while(iter != path.end()){
treeNode * pNode = *iter;
printf("%d ", pNode->data);
iter++;
}
printf("\n");
}
if(pRoot->pLeft != NULL){
printAllPathWithSum(pRoot->pLeft, sum, path, currentSum);
}
if(pRoot->pRight != NULL){
printAllPathWithSum(pRoot->pRight, sum, path, currentSum);
}
currentSum -= pRoot->data;
path.pop_back();
}