Guest User

Untitled

a guest
Jul 16th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. LinkedHashMap table;
  2. for each element e of array A
  3. if table.get(e) != null
  4. table.put( e, table.get(e) + 1 )
  5. else
  6. table.put( e, 0 )
  7.  
  8. //Do the same for array B
  9. for each element e of array B
  10. if table.get(e) != null
  11. table.put( e, table.get(e) + 1 )
  12. else
  13. table.put( e, 0 )
  14.  
  15. Collection union(Collection coll1, Collection coll2) {
  16. Set union = new HashSet(coll1);
  17. union.addAll(new HashSet(coll2));
  18. return union;
  19. }
  20.  
  21. Collection intersect(Collection coll1, Collection coll2) {
  22. Set intersection = new HashSet(coll1);
  23. intersection.retainAll(new HashSet(coll2));
  24. return intersection;
  25. }
  26.  
  27. Collection nonOverLap(Collection coll1, Collection coll2) {
  28. Collection result = union(coll1, coll2);
  29. result.removeAll(intersect(coll1, coll2));
  30. return result;
  31. }
Add Comment
Please, Sign In to add comment