-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubbleSort.c
More file actions
34 lines (32 loc) · 913 Bytes
/
BubbleSort.c
File metadata and controls
34 lines (32 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,temp,a[20];
printf(" Enter number of items \n");
scanf("%d",&n);
printf(" Enter the items to sort \n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(j=1;j<n;j++)
{
for(i=0;i<n-j;i++)
{
if(a[i]>=a[i+1])
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
}
}
printf(" The sorted array elements are \n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
}
/* Bubble sort is a simple sorting algorithm.This sorting algorithm is comparison-based
algorithm in which each pair of adjacent element is compared and the elements are swapped if they are
not in order.This algorithm is not suitable for large data sets as its average and worst case
complexity are of O(nsquare) where n is the number of items */