0% found this document useful (0 votes)
4 views

Bubble Sort

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Bubble Sort

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <iostream>

using namespace std;


template<class T>void bubblesort(T A[],int n)
{
for(int i=n-1;i>0;i--)
{
for(int j=0;j<i;j++)
{
if(A[j]>A[j+1])
{
T temp=A[j];
A[j]=A[j+1];
A[j+1]=temp;
}
}
}
};
template<class T>void printarray(T A[],int n)
{
for(int i=0;i<n;i++)
{
cout<<A[i]<<" ";
}
cout<<endl;
};
int main()
{
int A1[]={3,49999,5,600,7,1,2,3};
int n=sizeof(A1)/sizeof(int);
cout<<"\n before sorting::";
printarray(A1,n);
bubblesort(A1,n);
cout<<"\n after sorting::";
printarray(A1,n);
float A2[]={14.2,19.3,100.4,11.5,1.6,1.7,19.8};
float m=sizeof(A2)/sizeof(float);
cout<<"\n before sorting::";
printarray(A2,n);
bubblesort(A2,n);
cout<<"\n after sorting::";
printarray(A2,n);
return 0;

You might also like