Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. //using max func sort
  2. void printSorted(int a, int b, int c)
  3. {
  4. // Find maximum element
  5. int get_max = max(a, max(b, c));
  6.  
  7. // Find minimum element
  8. int get_min = -max(-a, max(-b, -c));
  9.  
  10. int get_mid = (a + b + c)
  11. - (get_max + get_min);
  12.  
  13. cout << get_min << " " << get_mid
  14. << " " << get_max;
  15. }
  16.  
  17. //swaping sort
  18. if (a > c)
  19. swap(a, c)
  20.  
  21. if (a > b)
  22. swap(a, b)
  23.  
  24. //Now the smallest element is the first one. Just check the 2-nd and 3-rd
  25.  
  26. if (b > c)
  27. swap(b, c);
  28.  
  29. //another solution: This takes 3 comparisons, but only two swaps.
  30. if (x < y) {
  31. if (z < x) swap(x,z);
  32. } else {
  33. if (y < z) swap(x,y);
  34. else swap(x,z);
  35. }
  36. if(z<y) swap(y,z);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement