排序算法
时间: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;
相关阅读 更多 +
排行榜 更多 +








![《房产达人2》 v1.11.1.0升级档+未加密补丁[RUNE]](https://images.phpfans.net/img/f1/20251224/logo_694bdc496c5a91.jpg)
![《终结者: 黑暗命运 - 反抗》 v1.08.1158升级档+未加密补丁[RUNE]](https://images.phpfans.net/img/f1/20251224/logo_694bdc464b6c41.jpg)
