Cod sursa(job #1156665)

Utilizator rockerboyHutter Vince rockerboy Data 27 martie 2014 20:52:07
Problema Radix Sort Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1 kb
#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] << " ";
}