分类:
2011-05-15 11:16:44
#include
using namespace std;
class countsort
{
public:
countsort(){};
~countsort()
{
delete[] a;
};
void input();
void output();
void count_sort();
private:
int *a;
int leng;
int k;
int getmax();
};
void countsort::count_sort()
{
int *c=new int[k+1];
int *b=new int[leng];
for(int i="0";i
c[i]=0;
}
for(int i="0";i
c[a[i]]++;
}
for(int i="1";i
c[i]+=c[i-1];
}
for(int i="leng-1";i>=0;i--)
{
b[c[a[i]]-1]=a[i];/*从0开始,固减1*/
c[a[i]]--;
}
for(int i="0";i
a[i]=b[i];
}
delete[] b;
delete[] c;
}
int countsort::getmax()
{
int max="a"[0];
for(int i="1";i
if(max {
max=a[i];
}
}
return max;
}
void countsort::input()
{
cout<<"请输入参加排序整数的个数\n";
cin>>leng;
a=new int[leng];
for(int i="0";i
cout<<"请输入第"< cin>>a[i];
}
k=getmax();
}
void countsort::output()
{
cout<<"现在数组中的数字分别为:\n";
for(int i="0";i
cout< }
cout<