Answer the question
In order to leave comments, you need to log in
How to build a tree like in the picture?
If someone has seen an algorithm for building such trees or knows the exact name, then I will be glad for any information that will help me build an identical tree from scratch.
Only I need exactly this, otherwise I was previously offered an algorithm for constructing a binary tree, but it does not fit.
Answer the question
In order to leave comments, you need to log in
Each vertex is a structure that contains data, a pointer to the parent, and a list of pointers to the children.
struct item {
int value;
item* parent;
vector<item*> children;
item(int v, item* p = nullptr) : value(v), parent(p) {}
void addChild(int value) {
children.push_back(new item(value, this));
}
~item() {
for(auto child : children)
delete *child;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question