Bubble Sort:- Bubble Sort is the one of most popular Sorting Algorithm that is used to sort the array of n size. The Worst case and Average Case Complexity of Bubble Sort is O(n)^2. The Below Code will show you how to implement the bubble sort to sort the array of n size.
#include<stdio.h>
#include<conio.h>
void main()
{
int size=0, a[100],i,j,temp;
clrscr();
printf("Enter the Size of Array:=");
scanf("%d",&size);
printf("Enter the Element of Array\n");
for(i=0;i<size;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<size-1;i++)
{
for(j=0;j<(size-i)-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("Sorted Array is :\n");
for(i=0;i<size;i++)
{
printf("\n%d",a[i]);
}
getch();
}
0 Comment(s)