(std::vector<std::vector<int>> *adj,
intu,
intv) {
47(*adj)[u - 1].push_back(v - 1);
48(*adj)[v - 1].push_back(u - 1);
59void explore(
conststd::vector<std::vector<int>> *adj,
intu,
60std::vector<bool> *visited) {
61(*visited)[u] =
true;
62 for(
autov : (*adj)[u]) {
79 intconnected_components = 0;
80std::vector<bool> visited(n,
false);
82 for(
inti = 0; i < n; i++) {
85connected_components++;
88 returnconnected_components;
94std::cout <<
"Running predefined tests..."<< std::endl;
95std::cout <<
"Initiating Test 1..."<< std::endl;
96std::vector<std::vector<int>> adj1(9, std::vector<int>());
105std::cout <<
"Test 1 Passed..."<< std::endl;
107std::cout <<
"Innitiating Test 2..."<< std::endl;
108std::vector<std::vector<int>> adj2(10, std::vector<int>());
123std::cout <<
"Test 2 Passed..."<< std::endl;
131 intvertices = int(), edges = int();
132std::cout <<
"Enter the number of vertices : ";
133std::cin >> vertices;
134std::cout <<
"Enter the number of edges : ";
137std::vector<std::vector<int>> adj(vertices, std::vector<int>());
139 intu = int(), v = int();
146std::cout << cc << std::endl;
void explore(const std::vector< std::vector< int > > *adj, int u, std::vector< bool > *visited)
Utility function for depth first seach algorithm this function explores the vertex which is passed in...
int getConnectedComponents(const std::vector< std::vector< int > > *adj)
Function that perfoms depth first search algorithm on graph and calculated the number of connected co...
void addEdge(std::vector< std::vector< int > > *adj, int u, int v)
Function that add edge between two nodes or vertices of graph.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4