After read this file , i want to do a selection sort...below are the selection sort programming that i get from google
#include <fstream>
#include <string>
#include <iomanip>
#include <iostream>
using namespace std;
void sortData( string fId[], int noOfRows);
int main ()
{
string Id[100];
int total[100], i = 0, num = 0;
ifstream inFile;
ofstream outFile;
inFile.open("jes.txt");
if (!inFile)
{
cout << "Cannot open the input file." << endl;
return 0;
}
outFile.open("jes2.txt");
while (!inFile.eof())
{
inFile >> Id[i] >> total[i] ;
i++;
}
for (i = 0; i < 3; i++)
{
cout<<" "<<Id[i]<<" "<<total[i] <<endl;
}
return 0;
}
selection sort
void selectionSort(int *array,int length)//selection sort function
{
int i,j,min,minat;
for(i=0;i<(length-1);i++)
{
minat=i;
min=array[i];
for(j=i+1;j<(length);j++) //select the min of the rest of array
{
if(min>array[j]) //ascending order for descending reverse
{
minat=j; //the position of the min element
min=array[j];
}
}
int temp=array[i] ;
array[i]=array[minat]; //swap
array[minat]=temp;
}
}
void printElements(int *array,int length) //print array elements
{
int i=0;
for(i=0;i<10;i++)
cout<<array[i]<<endl;
}
void main()
{
int a[]={9,6,5,23,2,6,2,7,1,8}; // array to sort
selectionSort(a,10); //call to selection sort
printElements(a,10); // print elements
}
but my problem is...how to call the input file that i was read into selection sort?
the example given is the number that has created.