Thursday, 5 December 2013

Bubble Sort



#include<iostream>
#include<conio.h>
 
 
using namespace std;
 
void main()
{

int a[100],i,n,p,j,temp;

cout<<"\n------------ BUBBLE SORT ------------ \n\n";

cout<<"Enter No. of Elements : ";
cin>>n;

cout<<"\nEnter Elements : \n";
for(i=1;i<=n;i++)
{
cin>>a[i];
}


for(p=1;p<=n-1;p++)             // Loop for Pass
{

for(j=1;j<=n-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];                      // Interchange Values
a[j]=a[j+1];
a[j+1]=temp;
}
}

}

cout<<"\nAfter Sorting : \n";
for(i=1;i<=n;i++)
{
cout<<a[i]<<endl;
}

getch();
}



Output :-

Bubble Sort

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Bluehost Coupons