#include #include #include #include using namespace std; list get_branches(int root); list > get_all_paths(int root) { list branches; list > allpaths; branches = get_branches(root); if (branches.empty()) { list v(1, root); allpaths.push_back(v); return allpaths; } BOOST_FOREACH(int b, branches) { list > partial_paths; partial_paths = get_all_paths(b); BOOST_FOREACH(list partial_path, partial_paths) { partial_path.push_front(root); allpaths.push_back(partial_path); } } return allpaths; } /* Graph generated by get_branches # 1 # / \ # 2 3 # / \ #4 5 */ list get_branches(int root) { if (root == 1) { int v[] = {2, 3}; list b(v, v+2); return b; } if (root == 2) { int v[] = {4, 5}; list b(v, v+2); return b; } list b; return b; } void print_paths(const list >& vv) { BOOST_FOREACH(list v, vv) { BOOST_FOREACH(int i, v) { cout< > vv; root = 1; vv = get_all_paths(root); print_paths(vv); return 0; }