BUBBLE SORT

The Bubble Sort algorithm for sorting of n numbers, represented by an array A[ 1 . . n ], proceeds by scanning the array from left to right. At each stage, compares adjacent pairs of numbers at positions A[ j ] and A[ j+1 ] and whenever a pair of adjacent numbers is found to be out of order, then the positions of the numbers are swapped.

Thus in the first iteration the largest number will reach its destination, but other numbers in the array, may not be in order. In each subsequent pass, one more number reaches its destination. Bubble Sort Programming in C

#include<stdio.h>
void main()
{
int a[]={80, 32, 28, 120, 20};
int i, j, temp;
for(i=1;i<5;i++)
{
for(j=0;j<5-i;j++)
{
if(a[j] > a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
for(i=0; i<5; i++)
{
printf("\t%d",a[i]);
}
}

QuestionSolves.com is an educational website that helps worldwide students in solving computer education related queries.

Also, different software like Visual Studio, SQL Server, Oracle etc. are available to download in different versions.

Moreover, QuestionSolves.com provides solutions to your questions and assignments also.

MORE TOPIC

WHAT WE DO

 Follow Us 