Re-write the following functions into template functions and test them by different data sets.
void sort(int X[], int n)
{
int temp;
for(int i=n-1; i>0; i--) //Start to compare the last element
for(int j=i-1; j>=0; j--) // with each of other elements
if(X[j]>X[i])
{
temp=X[j];
X[j]=X[i];
X[i]=temp;
}
}
void GetData(int A[], const int n, ifstream & read)
{
for (int i=0; i<n; i++)
read >> A[i];
}
void Print(int A[], const int n)
{
for (int i=0; i<n; i++)
cout << A[i] << " ";
cout << endl;
}
|
void main()
|
Num.txt: 8 4 7 8 2 3 5 1 6 9 10 20 Dec.txt TEX.txt: |