// Copyright 2017, University of Freiburg, // Chair of Algorithms and Data Structures. // Authors: Patrick Brosi // _____________________________________________________________________________ template std::vector*> > Algorithm::connectedComponents( const UndirGraph& g) { std::vector*>> ret; std::set*> visited; for (auto* n : g.getNds()) { if (!visited.count(n)) { ret.resize(ret.size() + 1); std::stack*> q; q.push(n); while (!q.empty()) { Node* cur = q.top(); q.pop(); ret.back().insert(cur); visited.insert(cur); for (auto* e : cur->getAdjList()) { if (!visited.count(e->getOtherNd(cur))) q.push(e->getOtherNd(cur)); } } } } return ret; }