-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBubbleSort.c
More file actions
38 lines (36 loc) · 824 Bytes
/
BubbleSort.c
File metadata and controls
38 lines (36 loc) · 824 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
35
36
37
38
/* Read n integers, store them in an array and sort the elements in the array using Bubble Sort algorithm */
#include<stdio.h>
void bubble (int[], int);
void main()
{
int a[50], size;
printf("\n Enter the size of the array: ");
scanf("%d", &size);
printf("\n Enter array of numbers : ");
for(int i=0; i<size; i++)
scanf("%d", &a[i]);
bubble(a,size);
}
void bubble ( int a[], int n)
{
int temp;
for(int i=0; i<n-1; i++)
{
for(int j=0; j<n-i-1; j++)
{
if(a[j] > a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
printf("\n After Pass %d : ", i);
for(int k=0; k<n; k++)
printf("%d | ", a[k]);
}
printf("\n The BubbleSorted Array is: ");
for(int i=0; i<n; i++)
printf("%d | ", a[i]);
printf("\n");
}