Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Function Template in C++

#include<iostream.h>
#include<conio.h>
template<class T>

void swap(T &a,T &b){
T temp;    temp=a;
a=b;        b=a;        }

template<class T1>

void fun(T1 x[],int n) {   
int i,j;
for(i=0;i<n-1;i++)
for(j=n-1;j<i;j--)
if(x[j]<x[j-1])
swap(x[j],x[j-1]);

cout<<"\nAscending Order:";
for(i=0;i<n;i++)        {
cout<<x[i];    }

cout<<"\nDescending Order:";
for(i=n-1;i>=0;i--)    {
cout<<x[i];    }    }

void main()
{
int k[]={3,4,5,2,1,0};float f[]={9.3,6.5,6.2,8.3,2.3,4.8};
clrscr();
fun(k,6);    fun(f,6);
getch();
}