Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- template <typename T>
- void MassiveReading (T* array, int n) {
- for (int i = 0; i < n; ++i) {
- cin >> array[i];
- }
- }
- template <typename T>
- int Sort(int n, T* array) {
- int result = 0;
- for (int i = 0; i < n - 1; i++) {
- for (int j = 0; j < n - i - 1; j++) {
- if (array[j] > array[j + 1]) {
- int temp = array[j];
- array[j] = array[j + 1];
- array[j + 1] = temp;
- result++;
- }
- }
- }
- return result;
- }
- int main() {
- int n;
- cin >> n;
- int* array = new int [n];
- MassiveReading(array, n);
- cout << Sort(n, array);
- delete[] array;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement