Skip to content

Commit fb90de5

Browse files
Merge pull request matthewsamuel95#892 from vmmc2/patch-5
Create Union-Find.cpp
2 parents 413233f + 9902517 commit fb90de5

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
void PreProcess(int array[], int x){
6+
int i;
7+
for(i = 0; i < x; i++){
8+
array[i] = i;
9+
}
10+
}
11+
bool Find(int array[], int A, int B){
12+
if(array[A] == array[B]){
13+
return true;
14+
}
15+
else{
16+
return false;
17+
}
18+
}
19+
//Change all entries from array[A] to array[B].
20+
void Union(int array[], int A, int B, int x){ // x is the size of my array
21+
int i;
22+
int temp = array[A];
23+
array[A] = array[B];
24+
for(i = 0; i < x; i++){
25+
if(array[i] == temp){
26+
array[i] = array[B];
27+
}
28+
}
29+
}
30+
int main(){
31+
int array[10]; // Array of integers. Each element represents a subset that contains only one element.
32+
PreProcess(array, 10);
33+
return 0;
34+
}

0 commit comments

Comments
 (0)