A Platform to LEARN | CODE | ACHIEVE



Start Coding
Take Challenge
Subscribe us !

Connect :



TO PERFORM BUBBLE SORT IN C

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


selection sort

Join us :



CODE OF GEEKS

A Platform to LEARN | CODE | ACHIEVE

Connect :



SHARE:



For any Queries,suggestions,feel free to Mail us at :
codeofgeeks@gmail.com

For reporting any kind of copyright voilation,mail us at : cogcopyclaim@gmail.com

© copyright CODE OF GEEKS