Bubble sort program........

Bubble sort
Bubble sort is also known as sinking sort.In it we compare adjacent pair and swap them if necessary causing.
This process is repeated until we get the sorted list.
#include<conio.h>#include<stdio.h>
#define max 5
void main()
{
int j,a[max],key,i,k;
clrscr();
printf("enter the array element");
for(i=0;i<=max;i++)
{
scanf("%d",&a[i]);
}
for(j=0;j<=max;j++)
{
for(k=max;k>=j+1;k--)
{
if(a[k]<a[k-1])
{
key=a[k];
a[k]=a[k-1];
a[k-1]=key;
}
}
}
for(i=0;i<=max;i++)
{
printf("%d",a[i]);
}
getch();
}
0 comments