Advertisement
Lirbo

Untitled

Jun 4th, 2023
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. public int GetMin()
  2. {
  3. int max = GetMax();
  4. while(!IsEmpty())
  5. RemoveFromSet(max);
  6. return max;
  7. }
  8.  
  9. public bool Equals(SetOfNumbers other)
  10. {
  11. while(!IsEmpty() || !other.IsEmpty())
  12. {
  13. if(IsEmpty() || other.IsEmpty()) return false;
  14. int a = GetMax();
  15. int b = other.GetMax();
  16. RemoveFromSet(a);
  17. other.RemoveFromSet(b);
  18. if(a != b) return false;
  19. }
  20. return true;
  21. }
  22.  
  23. public static SetOfNumbers Make(SetOfNumbers sn)
  24. {
  25. SetOfNumbers temp = new SetOfNumbers();
  26. SetOfNumbers evens = new SetOfNumbers();
  27. while(!sn.IsEmpty())
  28. {
  29. int max = sn.GetMax();
  30. sn.RemoveFromSet(max);
  31. temp.AddToSet(max);
  32. if(max % 2 == 0) evens.AddToSet(max);
  33. }
  34. while(!temp.IsEmpty())
  35. {
  36. int max = temp.GetMax();
  37. temp.RemoveFromSet(max);
  38. sn.AddToSet(max);
  39. }
  40. return evens;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement