#include #include #include #include class node { protected: string str; vector links; public: node(string s) { str = s; } static node * mk(string s) { return new node(s); } node * add(node * n) { links.push_back(n); return this; } string getname() { return str; } int getnumlinks() { return links.size(); } node * getlink(int i) { return links[i]; } }; void print(node * n, int depth = 0) { cout << setw(depth*5) << " " << n->getname() << "\n"; int num = n->getnumlinks(); for (int i = 0; i < num; i += 1) print(n->getlink(i), depth+1); } void main() { node * t1 = node::mk("ant") ->add(node::mk("bat") ->add(node::mk("egg") ->add(node::mk("kit")) ->add(node::mk("log"))) ->add(node::mk("fig")) ->add(node::mk("gat") ->add(node::mk("map")) ->add(node::mk("nut")) ->add(node::mk("old")) ->add(node::mk("pig")))) ->add(node::mk("cat") ->add(node::mk("hat"))) ->add(node::mk("dog") ->add(node::mk("ink") ->add(node::mk("qat")) ->add(node::mk("rat"))) ->add(node::mk("jug") ->add(node::mk("sud")) ->add(node::mk("tip")))); print(t1); }