Skip to content

Commit c8157a0

Browse files
committed
final working code for merge accounts using Disjoin set
1 parent f7e29f6 commit c8157a0

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/main/java/com/thealgorithms/graph/DisjointSet.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ void merge(int x, int y){
9898
}
9999

100100
/**
101-
* this is the code to merge email accounts
102-
* if two accounts share at least one email, they belong to same person.
101+
* This code merges email accounts.
102+
* If two accounts share at least one email address, they are considered to belong to the same person and are merged.
103103
* @param accountList
104104
* @return
105105
*/
@@ -155,3 +155,25 @@ public List<List<String>> accountsMerge(List<List<String>> accountList) {
155155
}
156156

157157
}
158+
159+
/**
160+
*
161+
* this the program for testing the above algorithm
162+
*
163+
public class DisjointSetMain {
164+
public static void main(String[] args) {
165+
List<List<String>> list = new ArrayList<>();
166+
list.add(new ArrayList<>(List.of("abc", "[email protected]","[email protected]")));
167+
list.add(new ArrayList<>(List.of("abc","[email protected]","[email protected]")));
168+
list.add(new ArrayList<>(List.of("Mary","[email protected]")));
169+
list.add(new ArrayList<>(List.of("John","[email protected]")));
170+
list.add(new ArrayList<>(List.of("John", "[email protected]", "[email protected]")));
171+
DisjointSet ds = new DisjointSet(list.size());
172+
List<List<String>> ans = ds.accountsMerge(list);
173+
for(List<String> val : ans){
174+
System.out.println(val);
175+
}
176+
}
177+
}
178+
179+
*/

0 commit comments

Comments
 (0)