Pagini recente » Cod sursa (job #2978943) | Cod sursa (job #2513546) | Cod sursa (job #580924) | Cod sursa (job #920040) | Cod sursa (job #1529570)
#include <fstream>
#include <vector>
using namespace std;
void radixSort(int a[], int n) {
int groupSize = 4;
vector < int > buckets[(1 << groupSize)];
for(int step = 0; step < 32; step += groupSize) {
for(int i = 0; i < (1 << groupSize); ++i) {
buckets[i].clear();
}
for(int i = 0; i < n; ++i) {
buckets[(a[i] & (((1 << groupSize) - 1) << step)) >> step].push_back(a[i]);
}
int k = 0;
for(int i = 0; i < (1 << groupSize); ++i) {
for(int j = 0; j < (int) buckets[i].size(); ++j) {
a[k++] = buckets[i][j];
}
}
}
}
int main() {
ifstream f("radixsort.in");
ofstream g("radixsort.out");
int n, a, b, c;
f >> n >> a >> b >> c;
int *v = new int [n];
v[0] = b;
for(int i = 1; i < n; ++i) {
v[i] = ((1LL * a * v[i - 1]) % c + b) % c;
}
radixSort(v, n);
for(int i = 0; i < n; i += 10) {
g << v[i] << " ";
}
g << "\n";
f.close();
g.close();
return 0;
}