//bubble sorting
#include<iostream>
using namespace std;
#include<conio.h>
template <class T>
void bubblesort(T a[],int n)
{
int i,j,temp;
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(a[j]<a[i])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
}
int main()
{
int a[50],i,n;
cout<<"enter number of elements do u want to sort :";
cin>>n;
cout<<"enter elements to sort:";
for(i=0;i<n;i++)
{
cin>>a[i];
}
bubblesort(a,n);
cout<<"after sorting the elements are....\n";
for(i=0;i<n;i++)
{
cout<<a[i]<<"\n";
}
_getch();
return 0;
}
#include<iostream>
using namespace std;
#include<conio.h>
template <class T>
void bubblesort(T a[],int n)
{
int i,j,temp;
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(a[j]<a[i])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
}
int main()
{
int a[50],i,n;
cout<<"enter number of elements do u want to sort :";
cin>>n;
cout<<"enter elements to sort:";
for(i=0;i<n;i++)
{
cin>>a[i];
}
bubblesort(a,n);
cout<<"after sorting the elements are....\n";
for(i=0;i<n;i++)
{
cout<<a[i]<<"\n";
}
_getch();
return 0;
}
No comments:
Post a Comment