L
L
latahs2015-05-08 17:53:58
Programming
latahs, 2015-05-08 17:53:58

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.
image.png
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

3 answer(s)
R
Roman Zhak, 2015-05-08
@romanzhak

www.bl.ocks.org/mbostock/4063570 using the d3js library

A
Alexander Movchan, 2015-05-09
@Alexander1705

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;
    }
}

Naturally, value can be of any other type.

N
Nikolay, 2015-05-08
@Nikolaos

mind maps here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question