Pagini recente » Cod sursa (job #1147357) | Cod sursa (job #2887371) | Cod sursa (job #1086024) | Cod sursa (job #2112677) | Cod sursa (job #1167400)
#include <fstream>
#include <vector>
using namespace std;
const int BIT_COUNT = 8;
const int MAX_STEPS = 4;
vector<int> Values;
void RadixSort(vector<int> &values, const int from, const int to, const int step = MAX_STEPS - 1) {
if (from >= to - 1 || step < 0)
return;
vector< vector<int> > buckets = vector< vector<int> >(1 << BIT_COUNT, vector<int>());
for (int i = from; i < to; ++i)
buckets[(values[i] >> (BIT_COUNT * step)) & ((1 << BIT_COUNT) - 1)].push_back(values[i]);
for (int b = 0, j = 0; b < (1 << BIT_COUNT); ++b) {
int nextj = j;
for (vector<int>::const_iterator v = buckets[b].begin(); v != buckets[b].end(); ++v, ++nextj)
values[from + nextj] = *v;
RadixSort(values, j, nextj, step - 1);
j = nextj;
}
}
void Read() {
ifstream cin("radixsort.in");
int n, a, b, c;
cin >> n >> a >> b >> c;
Values = vector<int>(n);
Values[0] = b;
for (int i = 1; i < n; ++i)
Values[i] = (1LL * Values[i - 1] * a + b) % c;
cin.close();
}
void Print() {
ofstream cout("radixsort.out");
for (int i = 0; i < int(Values.size()); i += 10)
cout << Values[i] << " ";
cout << "\n";
cout.close();
}
int main() {
Read();
RadixSort(Values, 0, int(Values.size()));
Print();
return 0;
}