Pagini recente » Cod sursa (job #511039) | Cod sursa (job #1630392) | Cod sursa (job #2072882) | Cod sursa (job #3246783) | Cod sursa (job #1156683)
#include <fstream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
ifstream f("radixsort.in");
ofstream g("radixsort.out");
typedef vector<unsigned int> Vektor;
typedef vector<unsigned int>::iterator Iterator;
typedef vector<unsigned int>::const_iterator cIterator;
unsigned long long x[10000005];
unsigned long long n, a, b, c, i, j, temp;
Iterator it;
void asd (int 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;
}
}
void radixsort()
{
for (i=0; i<30; i++)
asd (i);
}
int main()
{
f >> n >> a >> b >> c;
x[1] = b;
for (i=2; i<=n; i++)
{
x[i] = (x[i-1]*a+b)%c;
}
radixsort ();
//sort (x+1, x+n+1);
for (i=1; i<=n; i+=10)
g << x[i] << " ";
}