template<class T>
void sortfun(T arr[],int len)
{
int i, j;
T tmp;
for (i = 0;i < len-1;i++)
{
for (j = i;j < len - 1;j++)
{
if (arr[i] < arr[j + 1])
{
tmp = arr[i];
arr[i] = arr[j + 1];
arr[j+ 1] = tmp;
}
}
}
}
template<class T>
void printarr(T arr[], int len)
{
int i;
for (i = 0;i < len;i++)
cout << arr[i] << " ";
cout << endl;
}
void test()
{
int arrint[10] = { 8,6,4,2,1,5,2,7,9,0 };
char arrchar[10] = { 'b','w','e','t','y','u','i','p','b','g' };
sortfun(arrint, 10);
printarr(arrint, 10);
cout << "--------------------" << endl;
sortfun(arrchar, 10);
printarr(arrchar, 10);
}
void sortfun(T arr[],int len)
{
int i, j;
T tmp;
for (i = 0;i < len-1;i++)
{
for (j = i;j < len - 1;j++)
{
if (arr[i] < arr[j + 1])
{
tmp = arr[i];
arr[i] = arr[j + 1];
arr[j+ 1] = tmp;
}
}
}
}
template<class T>
void printarr(T arr[], int len)
{
int i;
for (i = 0;i < len;i++)
cout << arr[i] << " ";
cout << endl;
}
void test()
{
int arrint[10] = { 8,6,4,2,1,5,2,7,9,0 };
char arrchar[10] = { 'b','w','e','t','y','u','i','p','b','g' };
sortfun(arrint, 10);
printarr(arrint, 10);
cout << "--------------------" << endl;
sortfun(arrchar, 10);
printarr(arrchar, 10);
}