The Tree Generator — generate different kinds of trees by simple strings!

Revision en3, by ouuan, 2019-08-01 17:54:26

Want to generate different kinds of trees with simple functions or even a single string? The Tree Generator may be a good choice for you.

You can generate a tree by a single string:

Tree t("ch9,0st10,9"); // a tree consisting of a 10-node chain and a 10-node star at the bottom of it

You can add nodes by simple functions:

t.binary(10, 3); // add a 10-node binary tree with node 3 as its parent

You can shuffle the nodes and edges and output the tree:

cout << t;

You can customize the random function and the output function so that you can use it with testlib.h or print the edges with weights:

#include "testlib.h"

int myRandInt(int l, int r)
    return, r);
randint = myRandInt;

void myOutputEdge(ostream& os, int u, int pa)
    os << u + 1 << ' ' << pa + 1 << ' ' << randint(1, 10) << endl;
cout << t;

Why don't you try it? Just visit to clone/copy the codes, and read the GUIDEBOOK to learn how to use it.

However, it hasn't been well-tested, so bug reports are welcomed. My English is not very good, so any opinions for guidebook improvement are welcomed, too.


  Rev. Lang. By When Δ Comment
en3 English ouuan 2019-08-01 17:54:26 6
en2 English ouuan 2019-08-01 17:29:41 55
en1 English ouuan 2019-08-01 17:24:26 1386 Initial revision (published)