Pagini recente » Cod sursa (job #27524) | Cod sursa (job #2360918) | Cod sursa (job #1453067) | Cod sursa (job #3237144) | Cod sursa (job #1312883)
#include <iostream>
#include<list>
#include<fstream>
using namespace std;
#define B 10
#define MX 1000002
int a[MX], i,n, VfPrec[B+2], VfC[B+2] ;
list <int> LstPrec[B+2] , LstC[B+2];
ifstream f1("algsort.in");
ofstream f2("algsort.out");
void radix_s()
{
int i,p=100 ;
for (i=1; i<=n; i++)
LstPrec[a[i]%10 ].push_back(a[i] );
while (LstPrec[0].size() <n )
{
for (i=0; i<=10; i++)
LstC[i].clear();
for (i=0; i<=9; i++)
while (!LstPrec[i].empty() )
{
LstC[(LstPrec[i] .front()%p)/(p/10) ].push_back(LstPrec[i] .front() );
LstPrec[i] .pop_front();
}
for (i=0; i<10; i++)
LstPrec[i] =LstC[i] ;
p*=10;
}
for (i=1; i<=n; i++)
{
a[i]=LstC[0].front();
LstC[0].pop_front();
}
}
int main()
{
f1>>n;
for (i=1;i<=n; i++)
f1>>a[i];
radix_s();
for (i=1; i<=n; i++)
f2<<a[i]<<" ";
f2.close();
return 0;
}