how to use fstream library
have an assignment to read 10000 files from a file name"10000ia" and then after applying selection sort on it it should be print on another file say"10000sorted".what i have done i include fstream library
Code:
ifstream ifile;
ifile.open("10000ia.txt",ios::in);
ifile.seekg(0);
ifile>>;
ifile.close();
ofstream file;
file.open("10000.txt",ios::out);
file<<selection(a);
file.close();
system("pause");
return 0;
}
int selection(int a[10000])
{
int i,excount=0,comcount=0;
int min;
for( int i=0;i<10000;i++)
{
min=i;
for (int j=i+1;j<10000;j++)
{
if (a[min]>a[j])
{
min=j;
}
}
int temp=a[i];
a[i]=a[min];
a[min]=temp;
comcount=(15*(15+1))/2;
excount=excount+1;
}
cout<<"Number of exchange are:"<<excount<<"\n";
cout<<"Number of comparisons are:"<<comcount<<"\n";
return 0;
}