Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. template<class ItemType>
  2. ArrayBag Intersection(const ArrayBag& bag2)
  3. {
  4. ArrayBag<ItemType> ReturnBag;
  5. <ItemType> TempArray[this.maxItems];
  6. int i, j;
  7.  
  8. for (i = 0, i < this.maxItems + 1, i++)
  9. {
  10. TempArray[i] = NULL;
  11. }
  12.  
  13. for (i = 0, i<this.maxItems + 1, i++)
  14. {
  15. for (j = 0, j < this.Maxitems + 1, j++)
  16. {
  17. if (this.items[i] == bag2.items[j])
  18. {
  19. TempArray[i] = this.items[i];
  20. }
  21. }
  22. }
  23.  
  24. j = 0;
  25.  
  26. for (i = 0, i < this.maxItems + 1, i++)
  27. {
  28. if (TempArray[i] != NULL)
  29. {
  30. ReturnBag.items[j] = TempArray[i];
  31. j++;
  32. }
  33. }
  34.  
  35. return ReturnBag;
  36. }
  37.  
  38. template<class ItemType>
  39. ArrayBag Difference(const ArrayBag& bag2)
  40. {
  41. ArrayBag<ItemType> ReturnBag;
  42. <ItemType> TempArray[this.maxItems];
  43. int i, j;
  44.  
  45. for (i = 0, i < this.maxItems + 1, i++)
  46. {
  47. TempArray[i] = NULL;
  48. }
  49.  
  50. for (i = 0, i<this.maxItems + 1, i++)
  51. {
  52. for (j = 0, j < this.maxItems + 1, j++)
  53. {
  54. if (this.items[i] != bag2.items[j])
  55. {
  56. TempArray[i] = this.items[i];
  57. }
  58. }
  59. }
  60.  
  61. j = 0;
  62.  
  63. for (i = 0, i > this.maxItems + 1, i++)
  64. {
  65. if (TempArray[i] != NULL)
  66. {
  67. ReturnBag.items[j] = TempArray[i];
  68. j++;
  69. }
  70. }
  71.  
  72. return ReturnBag;
  73. }
  74.  
  75. template<class ItemType>
  76. ArrayBag Union(const ArrayBag& bag2)
  77. {
  78. ArrayBag<ItemType> ReturnBag;
  79.  
  80. if ((this.itemCount + bag2.itemCount) > this.maxItems)
  81. {
  82. return ReturnBag;
  83. }
  84.  
  85. <ItemType> TempArray[this.maxItems];
  86. int i(0), j(0);
  87.  
  88. for (i = 0, i < this.maxitems + 1, i++)
  89. {
  90. TempArray[i] = NULL;
  91. }
  92.  
  93. for (i = 0, i<this.maxItems + 1, i++)
  94. {
  95. TempArray[j] = this.items[i];
  96. j++;
  97. tempArray[j] = bag2.items[i];
  98. j++;
  99. }
  100.  
  101. j = 0;
  102.  
  103. for (i = 0, i < this.maxItems + 1, i++)
  104. {
  105. if (TempArray[i] != NULL)
  106. {
  107. ReturnBag.items[j] = TempArray[i];
  108. j++;
  109. }
  110. }
  111.  
  112. return ReturnBag;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement