#include <iostream>
using namespace std;
void SortAges(int ages[],int length)
{
if(ages==NULL||length<=0)
return;
const int oldsestages=99;
int i,age;
int timeofages[oldsestages+1];
for(i=0;i<=oldsestages;i++)
{
timeofages[i]=0;
}
for(i=0;i<length;i++ )
{
age=ages[i];
if(age<0||age>oldsestages)
cout<<"age out of range";
timeofages[age]++;
}
int index=0;
for(i=0;i<oldsestages;i++)
{
for(int j=0;j<timeofages[i];++j)
{
ages[index]=i;
++index;
}
}
}
void main()
{
int ages[12]={22,23,32,45,32,56,43,44,28,29,22,38};
SortAges(ages,12);
for(int i=0;i<12;i++)
cout<<ages[i]<<" ";
}
对公司所有员工的年龄排序
最新推荐文章于 2018-04-16 15:24:21 发布