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()
{
ifstream input("Num.txt");
ifstream input1("Dec.txt");
ifstream input2("TEX.txt");

int X[10];
double Y[8];
string Z[5];

GetData(X, 10, input);
GetData(Y, 8, input1);
GetData(Z, 5, input2);

sort(X, 10);
sort(Y, 8);
sort(Z, 5);

Print(X, 10);
Print(Y, 8);
Print(Z, 5);
}
 

 

Num.txt:
8 4 7 8 2 3 5 1 6 9 10 20

Dec.txt
8.8  5.7  8.9  3.4  1.2  2.6  45.9  1.9

TEX.txt:
Sherry  Hen  Sammy  Denise Watt