Pagini recente » Cod sursa (job #2170276) | Cod sursa (job #327752) | Cod sursa (job #2544490) | Cod sursa (job #876608) | Cod sursa (job #2268311)
#include <fstream>// RADIX SORT PENTRU LABORATOR ASD
#include <vector>
#include <queue>
#define NMAX 500001
using namespace std;
ifstream f("algsort.in");
ofstream g("algsort.out");
int a[NMAX], i, N, x, ok;
long long p = 1;
queue <int> Radix[11];
int main() {
f>>N;
for (i = 1; i <= N; i++) {
f>>x;
Radix[10].push(x);
}
ok = 1;
while (ok) {
ok = 0;
while (!Radix[10].empty()) {
x = Radix[10].front();
Radix[10].pop();
if(x > p) ok = 1;
Radix[(x / p) % 10].push(x);
}
p *= 10;
for (i = 0; i <= 9; i++) {
while (!Radix[i].empty()) {
x = Radix[i].front();
Radix[i].pop();
Radix[10].push(x);
}
}
}
while(!Radix[10].empty()) {
x = Radix[10].front();
g<<x<<' ';
Radix[10].pop();
}
return 0;
}