**template <class T>
void Rank(T a[], int n, int r[])
{**

for (int i=0;i<n;i++)

r[i]=0; //initialize rank array

for(int i=1;i<n;i++)

for(int j=0;j<i;j++)

if(a[j]<=a[i]) r[i]++;

else r[j]++;

**}**
template <class T>

void Rearrange(T a[],int n,int r[])

{

T *u=new T[n+1]}

for (int i=0;i<n;i++)

u[r[i]]=a[i]

for(int i =0;i<n;i++)

a[i]=u[i]

delete []u;

As you can see, the first function ranks the passed array and tells the second function which order to place the objects into. In order for the code to work properly, the comparison operators must be overloaded for the respective class T.