From 4c6c1dbe406b9c9ad7dcd925c018391063b3b542 Mon Sep 17 00:00:00 2001 From: Ayaan Khan Date: Mon, 18 May 2020 16:48:26 +0530 Subject: [PATCH] cpplint fixing --- graph/connected_components.cpp | 60 +++++++++++++++------------------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/graph/connected_components.cpp b/graph/connected_components.cpp index 4df4fb7c6..c3acad635 100644 --- a/graph/connected_components.cpp +++ b/graph/connected_components.cpp @@ -1,61 +1,55 @@ #include #include -using namespace std; +using std::vector; -class graph -{ +class graph { private: - vector> adj; - int cc; - void dfs(); - void explore(int, vector&); + vector> adj; + int connected_components; + void depth_first_search(); + void explore(int, vector&); public: - graph(int n): adj(n,vector()), cc(0) {} - void addEdge(int,int); - int getConnectedComponents() - { - dfs(); - return cc; + graph(int n): adj(n, vector()) { + connected_components = 0; + } + void addEdge(int, int); + int getConnectedComponents() { + depth_first_search(); + return connected_components; } }; -void graph::addEdge(int u, int v) -{ +void graph::addEdge(int u, int v) { adj[u-1].push_back(v-1); adj[v-1].push_back(u-1); } -void graph::dfs() -{ +void graph::depth_first_search() { int n = adj.size(); - vector visited(n,false); + vector visited(n, false); - for(int i = 0;i &visited) -{ +void graph::explore(int u, vector &visited) { visited[u] = true; - for(auto v : adj[u]) - { - if(!visited[v]) - explore(v,visited); + for (auto v : adj[u]) { + if (!visited[v]) { + explore(v, visited); + } } } -int main() -{ +int main() { graph g(4); g.addEdge(1,2); g.addEdge(3,2); - cout<