#include<iostream.h>
#include<conio.h>
#include<class T>
void bubble(T a[],int n)
{
for(int i=0;i<n-1;i++)
for(int j=n-1;i<j;j--)
if(a[j]<a[j-1])
{
swap(a[j],a[j-1]);
}
}
template<class x>
void swap(x &a,x &b)
{
x temp=a;
a=b;
b=temp;
}
void main()
{
int x[5],n;
float y[5];
clrscr();
cout<<"\n\t\t FUNCTION TEMPLATE";
cout<<"\n\t\t **************";
cout<<"\n Enter the n number :";
cin>>n;
cout<<"\n Enter the integer values of X array:";
for(int i=0;i<n;i++)
{
cin>>x[i];
}
cout<<"\n Enter the floating values of Y array:";
for(int j=0;j<n;j++)
{
cin>>y[j];
}
bubble(x,n);
bubble(y,n);
cout<<"\n Sorted x-array:";
for(i=0;i<n;i++)
{
cout<<x[i]<<"\n";
}
cout<<"\n Sorted y-array:";
for(j=0;j<n;j++)
{
cout<<y[j]<<"\n";
}
getch();
}
-------------
OUTPUT:
-------------
FUNCTION TEMPLATE
-------------------------------
Enter the n number:5
Enter the integer values of X array:
4
8
6
1
7
Enter the floating values of Y array:
2.1
4.5
7.8
2.8
5.7
Sorted X-array:
1
4
6
7
8
Sorted Y-array:
2.1
2.8
4.5
5.7
7.8
#include<conio.h>
#include<class T>
void bubble(T a[],int n)
{
for(int i=0;i<n-1;i++)
for(int j=n-1;i<j;j--)
if(a[j]<a[j-1])
{
swap(a[j],a[j-1]);
}
}
template<class x>
void swap(x &a,x &b)
{
x temp=a;
a=b;
b=temp;
}
void main()
{
int x[5],n;
float y[5];
clrscr();
cout<<"\n\t\t FUNCTION TEMPLATE";
cout<<"\n\t\t **************";
cout<<"\n Enter the n number :";
cin>>n;
cout<<"\n Enter the integer values of X array:";
for(int i=0;i<n;i++)
{
cin>>x[i];
}
cout<<"\n Enter the floating values of Y array:";
for(int j=0;j<n;j++)
{
cin>>y[j];
}
bubble(x,n);
bubble(y,n);
cout<<"\n Sorted x-array:";
for(i=0;i<n;i++)
{
cout<<x[i]<<"\n";
}
cout<<"\n Sorted y-array:";
for(j=0;j<n;j++)
{
cout<<y[j]<<"\n";
}
getch();
}
-------------
OUTPUT:
-------------
FUNCTION TEMPLATE
-------------------------------
Enter the n number:5
Enter the integer values of X array:
4
8
6
1
7
Enter the floating values of Y array:
2.1
4.5
7.8
2.8
5.7
Sorted X-array:
1
4
6
7
8
Sorted Y-array:
2.1
2.8
4.5
5.7
7.8
0 comments:
Post a Comment