From 9b72741a3182ad38213b95ccad14c046d7dcac19 Mon Sep 17 00:00:00 2001 From: Sesar Hersisson Date: Tue, 1 Oct 2019 12:37:01 +0000 Subject: [PATCH] Add unionFind.c to misc folder --- misc/unionFind.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 misc/unionFind.c diff --git a/misc/unionFind.c b/misc/unionFind.c new file mode 100644 index 00000000..8af9cc04 --- /dev/null +++ b/misc/unionFind.c @@ -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; +} \ No newline at end of file