MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / make_union

Function make_union

graph/code15.cpp:40–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38}
39
40void make_union(vector<int> &parent, vector<int> &rank, int a, int b)
41{
42 int first_parent = find(parent, a);
43 int second_parent = find(parent, b);
44
45 if (first_parent == second_parent)
46 {
47 return;
48 }
49
50 if (rank[first_parent] < rank[second_parent])
51 {
52 parent[first_parent] = second_parent;
53 }
54 else if (rank[first_parent] > rank[second_parent])
55 {
56 parent[second_parent] = first_parent;
57 }
58 else
59 {
60 parent[first_parent] = second_parent;
61 rank[second_parent]++;
62 }
63}
64
65void kruskal(vector<pair<int, int>> vec[], int v)
66{

Callers 1

kruskalFunction · 0.85

Calls 1

findFunction · 0.70

Tested by

no test coverage detected