排序算法
时间:2010-08-26 来源:snailshen
读文件读取一些正整数,算法复杂度为o(N)
利用数组下标来排序.比二分查找还快
int *a = new int [100];
for (int i=0;i<100;++i)
a[i] = 0;
ifstream ift ("1.txt");
char buf[100] = "\0";
while(ift.good()){
ift.getline(buf, sizeof(buf));
if(strlen(buf)==0) continue;
int itmp = atoi(buf);
a[itmp] = ++a[itmp];
cout<<"itmp="<<itmp<<" a[itmp]="<<a[itmp]<<endl;
}
for(int j=0;j<100;++j){
for(;a[j]!=0;){
cout<<j<<endl;
a[j] = --a[j];
}
}
delete [] a;
相关阅读 更多 +