Skip to content

Commit 1deaf6a

Browse files
authored
Create bubblesorting.c
1 parent 7a67996 commit 1deaf6a

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

sort/bubble_sort/c/bubblesorting.c

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include<stdio.h>
2+
void BubbleSort(int n, int a[]){
3+
int temp,count=0;
4+
for (int i = 0; i < n-1; i++)
5+
{
6+
for (int j = 0; j < n-i-1; j++)
7+
{
8+
if(a[j]>a[j+1]){
9+
temp=a[j];
10+
a[j]=a[j+1];
11+
a[j+1]=temp;
12+
count++;
13+
}
14+
}
15+
if(count==0){
16+
break;
17+
}
18+
}
19+
printf("The sorted array is:\n");
20+
for (int k = 0; k <n ; k++)
21+
{
22+
printf("%d ",a[k]);
23+
}
24+
25+
}
26+
int main(){
27+
int a[99],n;
28+
printf("Enter the size of the array:\n");
29+
scanf("%d",&n);
30+
printf("Enter the elements of the array:\n");
31+
for (int i = 0; i < n; i++)
32+
{
33+
scanf("%d",&a[i]);
34+
}
35+
BubbleSort(n,a);
36+
37+
return 0;
38+
}

0 commit comments

Comments
 (0)