Pages

Thursday, February 17, 2011

BUBBLE SORT

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[50],n,i,j,temp,l;
cout<<"enter the size of array (max 50)";
cin>>n;
cout<<"\n enter the array";
for(i=1;i<=n;i++)
cin>>a[i];
cout<<"\n sorted array is";
for(j=1;j<=n-1;j++)
{
for(int k=j+1;k<=n;k++)
{
if(a[j]>a[k])
{
temp=a[j];
a[j]=a[k];
a[k]=temp;
}
}
}
for(l=1;l<=n;l++)
cout<<a[l]<<"\t";
getch();

}







In this short video we take a look at the bubblesort sorting algorithm. It's one of the worst performing sorting algorithms, but it is also the easiest to explain. We also look at bubblesorts cousin shakersort.

No comments:

Post a Comment