Pagini recente » Cod sursa (job #2310545) | Cod sursa (job #721670) | Cod sursa (job #2930813) | Cod sursa (job #2666391) | Cod sursa (job #1473700)
#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; }