Advertisement
Guest User

Lab 06 Question 2

a guest
Sep 26th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. const int SIZE = 10;
  7.  
  8. template <class sortAlg>
  9.  
  10. sortAlg doSort(sortAlg arr[])
  11. {
  12. bool swapped = true;
  13. int j = 0;
  14. sortAlg tmp;
  15. while (swapped)
  16. {
  17. swapped = false;
  18. j++;
  19. for (int i = 0; i < SIZE - j; i++)
  20. {
  21. if (arr[i] > arr[i + 1])
  22. {
  23. tmp = arr[i];
  24. arr[i] = arr[i + 1];
  25. arr[i + 1] = tmp;
  26. swapped = true;
  27. }
  28. }
  29. }
  30. return 0;
  31. }
  32.  
  33.  
  34.  
  35. int main()
  36. {
  37. double arr[SIZE] = { 5.3, 6.2, 1.7, 4.3, 3.1, 2.8, 8.9, 7.1, 9.0, 0.3 };
  38.  
  39. doSort(arr);
  40.  
  41. for (int i = 0; i < SIZE; i++)
  42. {
  43. cout << arr[i] << " ";
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement