#include<iostream.h>
template <class T>
void sort(T a[],int n)
{
T temp;
int i,j;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[j]<a[i])
{
temp=a[j];
a[j]=a[i];
a[i]=temp;
}
}
}
}
void main()
{
int a[]={2,5,3,1,0,-1,4};
int i;
sort(a,7);
cout<<"\n Integer Number sorting\n";
for(i=0;i<7;i++)
cout<<"\t"<<a[i];
float b[]={2.5,5.5,3.5,1.5,2.3,-1.5,4.5};
sort(b,7);
cout<<"\n\n Floating Number sorting\n";
for(i=0;i<7;i++)
cout<<"\t"<<b[i];
double c[]={2.5234,5.5001,3.50002,1.50002,2.3001,-1.5001,4.5009};
sort(c,7);
cout<<"\n\n Double Number sorting\n";
for(i=0;i<7;i++)
cout<<"\t"<<c[i];
}
OUTPUT:
template <class T>
void sort(T a[],int n)
{
T temp;
int i,j;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[j]<a[i])
{
temp=a[j];
a[j]=a[i];
a[i]=temp;
}
}
}
}
void main()
{
int a[]={2,5,3,1,0,-1,4};
int i;
sort(a,7);
cout<<"\n Integer Number sorting\n";
for(i=0;i<7;i++)
cout<<"\t"<<a[i];
float b[]={2.5,5.5,3.5,1.5,2.3,-1.5,4.5};
sort(b,7);
cout<<"\n\n Floating Number sorting\n";
for(i=0;i<7;i++)
cout<<"\t"<<b[i];
double c[]={2.5234,5.5001,3.50002,1.50002,2.3001,-1.5001,4.5009};
sort(c,7);
cout<<"\n\n Double Number sorting\n";
for(i=0;i<7;i++)
cout<<"\t"<<c[i];
}
OUTPUT:
No comments:
Post a Comment