/* Bubble Sort Using Templets */
#include<iostream>
using namespace std;
template<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;
temp=&a;
&a=&b;
&b=temp;
}
int main()
{
int x[5],i,j;
float y[5];
cout<<"enter integer array:\n";
for(i=0;i<5;i++)
cin>>x[i];
cout<<"enter float array:\n";
for(j=0;j<5;j++)
cin>>y[j];
bubble(x,5);
bubble(y,5);
cout<<"sorted x-array \n";
for(i=0;i<5;i++)
cout<<x[i]<<" "<<"\n";
cout<<"sorted y-array \n";
for(j=0;j<5;j++)
cout<<y[j]<<" "<<"\n";
return(0);
}
I KRISHNAPRASAD PURSUING MY B.TECH IN C.R.REDDY COLLEGE OF ENGINEERING TRADE COMPUTER SCIENCES AND ENGINEERING. I'M HAPPY TO PRESENT ALL TYPE OF PROGRAMS. I HOPE U UTILISE THIS BLOG AND ENJOY YOUR PROGRAMMING. THESE PROGRAMS ARE BEST COMPILED IN TURBO C++ COMPILERS AND SUN JAVA COMPILERS
Thursday, November 25, 2010
TEMPLATES-BUBBLE SORT
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment