Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. class Zbior
  2. {
  3. private Hashtable hashtable;
  4. public Zbior()
  5. {
  6. hashtable = new Hashtable();
  7. }
  8. public void Dodaj(object item)
  9. {
  10. hashtable.Add(item, 1);
  11. }
  12. public Zbior Union(Zbior union)
  13. {
  14. Zbior z = new Zbior();
  15. foreach (DictionaryEntry item in union.hashtable)
  16. {
  17. z.Dodaj(item.Key);
  18. }
  19. foreach (DictionaryEntry item in hashtable)
  20. {
  21. if (!z.hashtable.Contains(item.Key))
  22. {
  23. z.Dodaj(item.Key);
  24. }
  25. }
  26. return z;
  27. }
  28. public Zbior Intersection(Zbior zbior)
  29. {
  30. Zbior z1 = new Zbior();
  31. foreach (DictionaryEntry item in zbior.hashtable)
  32. {
  33. if (hashtable.Contains(item.Key))
  34. z1.Dodaj(item.Key);
  35. }
  36. return z1;
  37. }
  38. public Zbior Difference(Zbior zbior)
  39. {
  40. Zbior z2 = new Zbior();
  41. foreach (DictionaryEntry item in hashtable)
  42. {
  43. if (!zbior.hashtable.Contains(item.Key))
  44. z2.Dodaj(item.Key);
  45. }
  46. return z2;
  47. }
  48. public void Display()
  49. {
  50. foreach (DictionaryEntry item in hashtable)
  51. {
  52. Console.Write(item.Key+" ");
  53. }
  54. }
  55. }
  56. static void Main(string[] args)
  57. {
  58. Zbior z1 = new Zbior();
  59. Zbior z2 = new Zbior();
  60. int[] Tab1 = { 1, 3, 5, 7, 9 };
  61. int[] Tab2 = { 2, 4, 6, 8 };
  62. foreach (var item in Tab1)
  63. {
  64. z1.Dodaj(item);
  65. }
  66. foreach (var item in Tab2)
  67. {
  68. z2.Dodaj(item);
  69. }
  70. Console.Write("Zbiór A:");
  71. z1.Display();
  72. Console.Write("\nZbiór B:");
  73. z2.Display();
  74.  
  75. Zbior z3 = z1.Union(z2);
  76. Console.Write("\nA + B: ");
  77. z3.Display();
  78.  
  79. Zbior z4 = z3.Intersection(z1);
  80. Console.Write("\n(A+B)*A: ");
  81. z4.Display();
  82.  
  83. Zbior z5 = z3.Difference(z1);
  84. Console.Write("\n(A+B)-A: ");
  85. z5.Display();
  86. Console.ReadKey();
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement