Advertisement
Guest User

Untitled

a guest
Oct 20th, 2014
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. package lab5;
  2.  
  3. public class ArraySetList<T> extends ArrayList<t> implements SetListInterface<T> {
  4.  
  5. public void add(T) {
  6. if (contains(element)==false)
  7. super.add(element);
  8.  
  9. else
  10. System.out.println("the element is already there");
  11.  
  12. //your overridden add() method here
  13. }
  14. //union of two sets
  15. public ArraySetList<T> union(ArraySetList<T> someSet) {
  16. SetListInterface<T> list = new SetListInterface<T>();
  17. int i;
  18. for(i=0;i<this.size();i++)
  19. {
  20. list.add(this.getNext());
  21. }
  22. for(i=0;i<someSet.size();i++)
  23. {
  24. list.add(someSet.getNext());
  25. }
  26.  
  27. return list;
  28.  
  29. }
  30.  
  31.  
  32. //intersection of 2 sets
  33. public ArraySetList<T> intersection(ArraySetList<T> someSet) {
  34. SetListInterface<T> list = new SetListInterface<T>();
  35.  
  36. for(int i=0;i<someSet.size();i++)
  37. {
  38. if(list.contains(someSet.getNext()))
  39. list.add(someSet.getNext());
  40.  
  41. }
  42. return list;
  43.  
  44.  
  45. }
  46.  
  47. //difference of 2 sets
  48. public ArraySetList<T> difference(ArraySetList<T> someSet) {
  49.  
  50. SetListInterface<T> list = new SetListInterface<T>();
  51. int i;
  52. for(i=0;i<this.size();i++){
  53. list.add(someSet.getNext());
  54. }
  55. for(i=0;i<someSet.size();i++){
  56. list.remove(someSet.getNext());
  57. }
  58.  
  59. return list;
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement