A Platform to LEARN | CODE | ACHIEVE
Connect :
BUBBLE SORT
Bubble sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort.
Worst-case performance : O(n2)
Best-case performance : O(n)
Average performance : O(n2)
Code
#include<stdio.h>
int main()
{
int a[100],size,i,j,temp;
printf(" ***** BUBBLE SORT - CODE OF GEEKS *****\n\n\n");
printf("ENTER THE SIZE OF ARRAY : ");
scanf("%d",&size;);
printf("ENTER THE ARRAY : ");
for(i=0;i<size;i++)
{
scanf("%d",&a;[i]);
}
for(i=1;i<=size;i++)
{
for(j=size-1;j>0;j--)
{
if(a[j]<a[j-1])
{
temp=a[j];
a[j]=a[j-1];
a[j-1]=temp;
}
}
}
printf("\nSORTED ARRAY : ");
for(i=0;i<size;i++)
{
printf("%d ",a[i]);
}
return 0;
}
Output
***** BUBBLE SORT - CODE OF GEEKS *****
ENTER THE SIZE OF ARRAY : 6
ENTER THE ARRAY :
98
56
84
46
38
96
SORTED ARRAY : 38 46 56 84 96 98
See this code in :
Also see :
Participate in our MONTHLY CHALLENGE,and get a chance to get listed on our site and win the TITLE of "MR.GEEK".
Join us :
Connect :
SHARE:
For any Queries,suggestions,feel free to Mail us at :
[email protected]
For reporting any kind of copyright voilation,mail us at : [email protected]
© copyright CODE OF GEEKS