Cod sursa(job #1473700)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 20 august 2015 00:07:24
Problema Sortare prin comparare Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.75 kb
#include <fstream>
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <utility>
#include <array>
#include <queue>
using namespace std;

template <typename It>
void my_sort(const It s, const It d){
	array<queue<int>, 256> buckete;
	for(int i = 0; i < 4; ++i){
		for(auto it = s; it != d; ++it){
			buckete[(*it >> 8*i) & 0xff].push(*it); }
		auto it = s;
		for(int j = 0; j < 256; ++j){
			while(!buckete[j].empty()){
				*it++ = buckete[j].front();
				buckete[j].pop(); } } } }

int main(){
	ifstream f("algsort.in");
	ofstream g("algsort.out");
	int n;
	f >> n;
	vector<int> v(n);
	copy_n(istream_iterator<int>(f), n, begin(v));
	my_sort(begin(v), end(v));
	copy(begin(v), end(v), ostream_iterator<int>(g, " "));
	return 0; }