COMBINATORIAL_BLAS
1.6
Loading...
Searching...
No Matches
DisjSets.cpp
Go to the documentation of this file.
1
2
7
DisjSets::DisjSets
(
int
numElements ) : s( numElements, -1 )
8
{
9
}
10
18
void
DisjSets::unionSets
(
int
root1,
int
root2 )
19
{
20
if
( s[ root2 ] < s[ root1 ] )
// root2 is deeper
21
s[ root1 ] = root2;
// Make root2 new root
22
else
23
{
24
if
( s[ root1 ] == s[ root2 ] )
25
--s[ root1 ];
// Update height if same
26
s[ root2 ] = root1;
// Make root1 new root
27
}
28
}
29
30
36
int
DisjSets::find
(
int
x )
const
37
{
38
if
( s[ x ] < 0 )
39
return
x;
40
else
41
return
find
( s[ x ] );
42
}
43
44
50
int
DisjSets::find
(
int
x )
51
{
52
if
( s[ x ] < 0 )
53
return
x;
54
else
55
return
s[ x ] =
find
( s[ x ] );
56
}
57
DisjSets::find
int find(int x) const
Definition
DisjSets.cpp:36
DisjSets::DisjSets
DisjSets(int numElements)
Definition
DisjSets.cpp:7
DisjSets::unionSets
void unionSets(int root1, int root2)
Definition
DisjSets.cpp:18
mfiles
DisjSets.cpp
Generated by
1.9.8