Advertisement
Guest User

Untitled

a guest
May 24th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. // prototypes for the other functions used
  5. void compare(int*, int*);
  6. void swap(int*, int*);
  7.  
  8. // sends the inputs in pairs to sortItOut for simplier sorting
  9. void smallSort2(int* a, int* b, int* c)
  10. {
  11.     compare(a, b);
  12.     compare(a, c);
  13.     compare(b, c);
  14. }
  15.  
  16. // determines if the inputs need to be sorted, or if they are already in the
  17. // correct order
  18. void compare(int* a, int* b)
  19. {
  20.     if (*a > *b)
  21.         swap(a, b);
  22. }
  23.  
  24. // if the values needed to be swapped then they will have their positions
  25. // "switched" in memory, that is why they are passed by reference
  26. void swap(int* first, int* second)
  27. {
  28.     int temp = *first;
  29.     *first = *second;
  30.     *second = temp;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement