Cod sursa(job #551549)

Utilizator blastoiseZ.Z.Daniel blastoise Data 10 martie 2011 21:06:03
Problema Sortare prin comparare Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.66 kb
#include <fstream>
#include <string.h>

using namespace std;

int i,N;
int v[500001],x[500001];
int count[256],index[256];

inline void radix(int byte,int a[],int b[])
{
	int i;

	byte<<=3;

	memset(count,0,sizeof(count));

	for(i=0;i<N;i++) ++count[(a[i]>>byte)&255];

	index[0]=-1;
	for(i=1;i<256;i++) index[i]=index[i-1]+count[i-1];
	for(i=0;i<N;i++) b[++index[(a[i]>>byte)&255]]=a[i];

}

int main()
{
	ifstream in("algsort.in");
	ofstream out("algsort.out");

	in>>N;

	for(i=0;i<N;i++) in>>v[i];

	radix(0,v,x);
	radix(1,x,v);
	radix(2,v,x);
	radix(3,x,v);

	for(i=0;i<N-1;i++) out<<v[i]<<' ';
	out<<v[N-1]<<'\n';

	return 0;
}