分类: C/C++
2010-08-26 12:32:19
读文件读取一些正整数,算法复杂度为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="<
for(int j=0;j<100;++j){
for(;a[j]!=0;){
cout<
}
}
delete [] a;