Pagini recente » Cod sursa (job #1946475) | Cod sursa (job #1546244) | Cod sursa (job #1702929) | Cod sursa (job #359831) | Cod sursa (job #2944046)
//Bucket Sort
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
ifstream in ("algsort.in");
ofstream out("algsort.out");
#define NoBuckets 50000
#define maxN 500000
#define BucketCap 1000
vector <int> bucket[NoBuckets+1];
int v[maxN+1],n;
void GetBuckets(){
for(int i=1;i<=n;i++){
bucket[v[i]/BucketCap].push_back(v[i]);
}
}
void BucketSort(){
for(int i=0;i<NoBuckets;i++){
sort(bucket[i].begin(),bucket[i].end());
for(auto x : bucket[i]){
out<<x<<" ";
}
}
}
int main(){
in>>n;
for(int i=1;i<=n;i++){
in>>v[i];
}
GetBuckets();
BucketSort();
}