-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathBucket_sort_in_c++.cpp
62 lines (49 loc) · 1.14 KB
/
Bucket_sort_in_c++.cpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mp make_pair
#define pb push_back
#define loop(x,n) for(int x = 0; x < n; x++)
#include <bits/stdc++.h>
using namespace std;
long long int input(){
ll n;
cin>>n;
return n;
}
void bucketSort(long double arr[],ll n)
{
vector<long double> b[n];
for (int i = 0; i < n; i++) {
int bi = n * arr[i];
b[bi].push_back(arr[i]);
}
for (int i = 0; i < n; i++)
sort(b[i].begin(), b[i].end());
int index = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < b[i].size(); j++)
arr[index++] = b[i][j];
}
int main() {
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
ios::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
int t;
cin>>t;
while(t--){
ll n=input();
long double arr[n];
loop(i,n){
cin>>arr[i];
}
bucketSort(arr,n);
loop(x,n){
cout<<arr[x]<<" ";
}
cout<<"\n";}
}