Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. template <typename T>
  6. void MassiveReading (T* array, int n) {
  7. for (int i = 0; i < n; ++i) {
  8. cin >> array[i];
  9. }
  10. }
  11.  
  12. template <typename T>
  13. int Sort(int n, T* array) {
  14. int result = 0;
  15. for (int i = 0; i < n - 1; i++) {
  16. for (int j = 0; j < n - i - 1; j++) {
  17. if (array[j] > array[j + 1]) {
  18. int temp = array[j];
  19. array[j] = array[j + 1];
  20. array[j + 1] = temp;
  21. result++;
  22. }
  23. }
  24. }
  25. return result;
  26. }
  27.  
  28. int main() {
  29. int n;
  30. cin >> n;
  31. int* array = new int [n];
  32. MassiveReading(array, n);
  33. cout << Sort(n, array);
  34. delete[] array;
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement