| nothing!!!! #include<cstdlib> #include<iostream> #include<fstream> //#include<vector> using namespace std; void swapInt(int &a,int &a2) { int temp=a; a=a2; a2=temp; } void creatFile(char *file) { ofstream fout; fout.open(file,ios::out); int tempRand; for(int i=0;i<50;i++) { tempRand=(int)rand()/(RAND_MAX/100); if(tempRand) fout<<tempRand<<endl; else i--; } fout.close(); } void readFile(char *file,int arr[50]) { ifstream fin; fin.open(file,ios::in ); for(int j=0;j<50;j++) { fin>>arr[j]; } fin.close(); } void bubbleSort(int a[], int n=50)//冒泡排序法 { bool change; for(int i=n-1,change=true;i>=1&&change;i--) { change=false; for(int j=0;j<i;j++) if(a[j]>a[j+1]) { swapInt(a[j],a[j+1]); change=true; } } } int main() { char *file="f:\test228.txt"; int a[50]; srand(1); creatFile(file); readFile(file,a); bubbleSort(a); for(int i=0;i<50;i++) { cout<<a[i]<<endl; } /* char *file2="f:\test2280.txt"; int a2[50]; srand(2); creatFile(file2); readFile(file2,a2); for(int i=0;i<50;i++) { cout<<a2[i]<<endl; } */ return 0; } |