mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-22 21:41:59 +03:00
Add unionFind.c to misc folder
This commit is contained in:
parent
90f9c0a39b
commit
9b72741a31
22
misc/unionFind.c
Normal file
22
misc/unionFind.c
Normal file
@ -0,0 +1,22 @@
|
||||
int p[1000000];
|
||||
int find(int x)
|
||||
{
|
||||
if (p[x] == x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
else
|
||||
{
|
||||
p[x] = find(p[x]);
|
||||
return p[x];
|
||||
}
|
||||
}
|
||||
// Call to function join(int x, int y) to join PARAM x and y
|
||||
void join(int x, int y)
|
||||
{
|
||||
p[find(x)] = find(y);
|
||||
}
|
||||
|
||||
int main() {
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user