A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/df/ddd/connected__components_8cpp_source.html below:

TheAlgorithms/C++: graph/connected_components.cpp Source File

Go to the documentation of this file. 46void addEdge

(std::vector<std::vector<int>> *adj,

int

u,

int

v) {

47

(*adj)[u - 1].push_back(v - 1);

48

(*adj)[v - 1].push_back(u - 1);

59void explore

(

const

std::vector<std::vector<int>> *adj,

int

u,

60

std::vector<bool> *visited) {

61

(*visited)[u] =

true

;

62 for

(

auto

v : (*adj)[u]) {

79 int

connected_components = 0;

80

std::vector<bool> visited(n,

false

);

82 for

(

int

i = 0; i < n; i++) {

85

connected_components++;

88 return

connected_components;

94

std::cout <<

"Running predefined tests..."

<< std::endl;

95

std::cout <<

"Initiating Test 1..."

<< std::endl;

96

std::vector<std::vector<int>> adj1(9, std::vector<int>());

105

std::cout <<

"Test 1 Passed..."

<< std::endl;

107

std::cout <<

"Innitiating Test 2..."

<< std::endl;

108

std::vector<std::vector<int>> adj2(10, std::vector<int>());

123

std::cout <<

"Test 2 Passed..."

<< std::endl;

131 int

vertices = int(), edges = int();

132

std::cout <<

"Enter the number of vertices : "

;

133

std::cin >> vertices;

134

std::cout <<

"Enter the number of edges : "

;

137

std::vector<std::vector<int>> adj(vertices, std::vector<int>());

139 int

u = int(), v = int();

146

std::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