Answer the question
In order to leave comments, you need to log in
How to find the sums of consecutive nodes in a binary tree?
Given: binary tree (tree algorithm written by hand ). Number S.
You need to find a sequence of nodes (only from top to bottom or vice versa) in a binary tree, the sum of which is equal to S .
For example: there is a binary tree, and the number S = 9.
Solution: 3+6, 4+5, 9.
p.s. it is desirable that it be a separate class that has access to the binTree class
#pragma once
class binTree
{
protected:
struct Node
{
int Value;
Node * pLeft;
Node * pRight;
Node * pParent;
Node(int x) :Value(x), pLeft(NULL), pRight(NULL), pParent(NULL) {}
};
Node * m_pRoot;
void InoderTreeWalk(Node * x);
Node * TreeSuccessor(Node *x);
Node * TreeMin(Node * x);
public:
binTree();
~binTree();
virtual void TreeInsert(int k);
Node * TreeSearch(Node * X, int k);
void ShowTree();
int Root();
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question