DavidNorgren

Untitled

May 19th, 2014
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include "UnionSet.h"
  2.  
  3. UnionSet::UnionSet(IntSet *set1, IntSet *set2) {
  4.     s1 = set1;
  5.     s2 = set2;
  6.     count = s1->GetCount() + s2->GetCount();
  7. }
  8.  
  9. void UnionSet::Add(int elem) {
  10.     if (Contains(elem)) return;
  11.     s2->Add(elem);
  12.     count++;
  13. }
  14.  
  15. IntSet* UnionSet::Union(IntSet *other) {
  16.     return new UnionSet(this, other);
  17. }
  18.  
  19.  
  20. void UnionSet::Rewind() {
  21.     s1->Rewind();
  22.     s2->Rewind();
  23.     iterator = 0;
  24. }
  25. bool UnionSet::IsEnd() {
  26.     return s2->IsEnd();
  27. }
  28. int UnionSet::Current() {
  29.     if (s1->IsEnd()) return s2->Current();
  30.     return s1->Current();
  31. }
  32. void UnionSet::MoveNext() {
  33.     if (s1->IsEnd()) s2->MoveNext();
  34.     else s1->MoveNext();
  35.     iterator++;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment