From 5f873a7b111555fb803da81816526ac4e7fc7c93 Mon Sep 17 00:00:00 2001 From: Sagar Pandya Date: Wed, 28 Oct 2020 21:17:16 +0530 Subject: [PATCH] readability improved --- graph/connected_components_with_dsu.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/graph/connected_components_with_dsu.cpp b/graph/connected_components_with_dsu.cpp index c582d6f58..cd64a1bb2 100644 --- a/graph/connected_components_with_dsu.cpp +++ b/graph/connected_components_with_dsu.cpp @@ -42,21 +42,21 @@ int find_set(int val) { } /** * @brief To join 2 components to belong to one - * @param a 1st component - * @param b 2nd component + * @param node1 1st component + * @param node2 2nd component * @returns void */ -void union_sets(int a, int b) { - a = find_set(a); // find the parent of a - b = find_set(b); // find the parent of b +void union_sets(int node1, int node2) { + node1 = find_set(node1); // find the parent of node1 + node2 = find_set(node2); // find the parent of node2 // If parents of both nodes are not same, combine them - if (a != b) { - if (connected_set_size[a] < connected_set_size[b]) { - std::swap(a, b); // swap both components + if (node1 != node2) { + if (connected_set_size[node1] < connected_set_size[node2]) { + std::swap(node1, node2); // swap both components } - parent[b] = a; // make a node as parent of b node. - connected_set_size[a] += connected_set_size[b]; // sum the size of both as they combined + parent[node2] = node1; // make node1 as parent of node2. + connected_set_size[node1] += connected_set_size[node2]; // sum the size of both as they combined } } /**