Pagini recente » Cod sursa (job #1336931) | Cod sursa (job #167960) | Cod sursa (job #2768484) | Cod sursa (job #2936658) | Cod sursa (job #1156665)
#include <fstream>
#include <vector>
#include <cstring>
using namespace std;
ifstream f("radixsort.in");
ofstream g("radixsort.out");
typedef vector<int> Vektor;
typedef vector<int>::iterator Iterator;
typedef vector<int>::const_iterator cIterator;
int x[10000005];
int n, a, b, c, i, j, temp;
Iterator it;
void radixsort()
{
for (i=0; i<25; i++)
{
Vektor temp[2];
for (j = 1; j<=n; j++)
{
temp[(x[j]>>i)&1].push_back(x[j]);
}
n = 0;
for (it = temp[0].begin(); it<temp[0].end(); it++)
{
n++;
x[n] = *it;
}
for (it = temp[1].begin(); it<temp[1].end(); it++)
{
n++;
x[n] = *it;
}
}
}
int main()
{
f >> n >> a >> b >> c;
x[1] = b;
g << b << "\n";
for (i=2; i<=n; i++)
{
x[i] = (x[i-1]*a+b)%c;
}
radixsort ();
for (i=1; i<=n; i+=10)
g << x[i] << " ";
}