Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- int main()
- {
- int n;
- int k;
- int op=0;
- int mas[100];
- cout << "razmer:";
- cin >> n;
- cout << "massiv:";
- for (int i = 0; i < n; i++)
- {
- cin >> mas[i];
- }
- for (k = n / 2;k > 0;k /= 2)
- {
- for (int i =n-1; i >= 0; i--)
- {
- int t = i;
- while (t-k>=0)
- {
- if (mas[t] < mas[t - k]) { swap(mas[t], mas[t - k]); op++; }
- t -= k;
- }
- }
- }
- if (mas[n-1] < mas[n-2]) { swap(mas[n - 1], mas[n - 2]); op++;}
- cout << "sort:";
- for (int i = 0; i < n; i++)
- {
- cout << mas[i]<<" ";
- }
- cout << endl;
- cout << "operazii:"<< op << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment