Xpode.com        Click here to Print this article.

Program to perform BUBBLE SORT in C++

/********************************/
/*PROGRAM TO PREFORM BUBBLE SORT*/
/********************************/



#include < stdio.h>
#include < conio.h>

void main()
{
int a[10],n,i,j,temp,flag;
clrscr();
printf("Enter the size of array: ");
scanf("%d",&n);
printf("\nEnter the elements of array:\n");

for( i= 0; i < n ; i++)
{
scanf("%d",&a[i]);
}

for(i= 0 ; i < n-1; i++)
{
flag=0;
for( j = 0; j < n-i ; j++)
{

if(a [ j ] > a [ j + 1 ] )
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
flag=1;
}
}

if(flag==0)
{
break;
}
}

printf(" \n After sorting the elements of array are: \n ");
for( i = 0 ; i < n ; i++ )
{
printf(" %d ",a [ i ]);
}
getch();
}



http://
http://

Contributed by:
Rohit kakria
I am software developer

Resourse address on xpode.com
http://www.xpode.com/Print.aspx?Articleid=332

Click here to go on website