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:

t.shuffleNodes();
t.shuffleEdges();
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 rnd.next(l, 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 https://github.com/ouuan/Tree-Generator 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.

#### History

Revisions

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