Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- using namespace std;
- int main()
- {
- const short size = 13;
- short size2 = 0;
- //short arr[size]{ 1,3,0,4,2,9,7,6,5,8 };
- short arr[size]{ 75, 11, 17, 78, 75, 2, 98, 27, 56, 4, 99, 16, 65 };
- /*short arr[size]{};
- srand(time(NULL));
- for (short i = 0; i < size; i++)
- {
- arr[i] = rand() % 101;
- }*/
- for (short a : arr)
- {
- cout << a << ' ';
- }
- cout << endl;
- short counter = 0;
- for (short i = 2;; i *= 2)
- {
- for (short j = 0;; j += i)
- {
- short temp = 0;
- for (short k = j; k + 1 <= j + i; k++)
- {
- short min = k;
- for (short m = k + 1; m < j + i && m < size; m++)
- {
- if (arr[min] > arr[m])
- {
- min = m;
- }
- }
- if (min != k)
- {
- temp = arr[min];
- arr[min] = arr[k];
- arr[k] = temp;
- }
- counter++;
- }
- if (j > size - 1)
- {
- break;
- }
- }
- if (i > size - 1)
- {
- break;
- }
- }
- for (short a : arr)
- {
- cout << a << ' ';
- }
- cout << endl << counter << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement