-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathShuffle integers.cpp
More file actions
46 lines (39 loc) · 818 Bytes
/
Copy pathShuffle integers.cpp
File metadata and controls
46 lines (39 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<bits/stdc++.h>
using namespace std;
void shuffle(int);
void _shuffle(int[], int, int);
int main(){
int t, n;
cin >> t;
while(t--){
cin >> n;
shuffle(n);
cout << endl;
}
return 0;
}
void shuffle(int n){
int arr[n], m;
for(int i = 0; i < n; i++)
cin >> arr[i];
_shuffle(arr, 0, n - 1);
for(int i = 0; i < n; i++)
cout << arr[i] << " ";
}
void _shuffle(int arr[], int s, int e){
int m, mf, ss;
if(s > e)
return;
if(s + 1 == e)
return;
m = (s + e) / 2;
mf = (s + m) / 2;
ss = m + 1;
for(int i = mf + 1; i <= m; i++)
swap(arr[i], arr[ss++]);
for(int i = s; i <= e; i++)
cout << arr[i] << " ";
cout << endl;
_shuffle(arr, s, m);
_shuffle(arr, m + 1, e);
}