Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //using max func sort
- void printSorted(int a, int b, int c)
- {
- // Find maximum element
- int get_max = max(a, max(b, c));
- // Find minimum element
- int get_min = -max(-a, max(-b, -c));
- int get_mid = (a + b + c)
- - (get_max + get_min);
- cout << get_min << " " << get_mid
- << " " << get_max;
- }
- //swaping sort
- if (a > c)
- swap(a, c)
- if (a > b)
- swap(a, b)
- //Now the smallest element is the first one. Just check the 2-nd and 3-rd
- if (b > c)
- swap(b, c);
- //another solution: This takes 3 comparisons, but only two swaps.
- if (x < y) {
- if (z < x) swap(x,z);
- } else {
- if (y < z) swap(x,y);
- else swap(x,z);
- }
- if(z<y) swap(y,z);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement