Guest User

Untitled

a guest
Jan 19th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. //Set A with values 6,2,7
  2. val a = new NonEmpty(2, new NonEmpty(1, new Empty, new Empty), new NonEmpty(3, new Empty, new Empty))
  3. println("SET A")
  4. print("Set A contient 1: ")
  5. println(a contains 1)
  6. print("Set A contient 2: ")
  7. println(a contains 2)
  8. print("Set A contient 3: ")
  9. println(a contains 3)
  10. print("Set A contient 4: ")
  11. println(a contains 4)
  12. println("-----------")
  13. //Set B with values 6,1,7
  14. val b = new NonEmpty(2, new NonEmpty(1, new Empty, new Empty), new NonEmpty(4, new Empty, new Empty))
  15. println("SET B")
  16. print("Set B contient 1: ")
  17. println(b contains 1)
  18. print("Set B contient 2: ")
  19. println(b contains 2)
  20. print("Set B contient 3: ")
  21. println(b contains 3)
  22. print("Set B contient 4: ")
  23. println(b contains 4)
  24. println("-----------")
  25.  
  26. //Set C: intersection of set A and set B
  27. val c = a.intersect(b);
  28. println("Set C: Intersection of SET A and SET B")
  29. print("Set C contient 1: ")
  30. println(c contains 1)
  31. print("Set C contient 2: ")
  32. println(c contains 2)
  33. print("Set C contient 3: ")
  34. println(c contains 3)
  35. print("Set C contient 4: ")
  36. println(c contains 4)
  37. println("-----------")
  38.  
  39.  
  40. //Set D: even numbers of set A
  41. val d = b.filter(x => (x%2 == 0))
  42. println("SET D: filter of even number of set B:")
  43. print("Set D contient 1: ")
  44. println(d contains 1)
  45. print("Set D contient 2: ")
  46. println(d contains 2)
  47. print("Set D contient 3: ")
  48. println(d contains 3)
  49. print("Set D contient 4: ")
  50. println(d contains 4)
  51. println("-----------")
  52.  
  53. //Set E: intersection of Set A and set B using the second way to compute the intersection
  54. val e = a.intersect2(b)
  55. println("SET E: Intersection of set A and set B using the second method")
  56. print("Set E contient 1: ")
  57. println(e contains 1)
  58. print("Set E contient 2: ")
  59. println(e contains 2)
  60. print("Set E contient 3: ")
  61. println(e contains 3)
  62. print("Set E contient 4: ")
  63. println(e contains 4)
  64. println("-----------")
Add Comment
Please, Sign In to add comment