Cod sursa(job #2136297)

Utilizator inquisitorAnders inquisitor Data 19 februarie 2018 20:17:17
Problema Sortare prin comparare Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.73 kb
#include <cstdio>
#include <queue>

int N, x;

std :: queue<int> bucket1[65536], bucket2[65536];

int main()
{
    freopen("algsort.in", "r", stdin);
    freopen("algsort.out", "w", stdout);

    scanf("%d", &N);

    for(int i = 0; i < N; ++i)
    {
        scanf("%d", &x);

        bucket1[x & 65535].push(x);
    }

    for(int i = 0; i != 65536; ++i)
    {
        while(!bucket1[i].empty())
        {
            x = bucket1[i].front(); bucket1[i].pop();

            bucket2[x >> 16 & 65535].push(x);
        }
    }

    for(int i = 0; i != 65536; ++i)
    {
        while(!bucket2[i].empty())
        {
            printf("%d ", bucket2[i].front()); bucket2[i].pop();
        }
    }

    return 0;
}