forked from alfinandika/bubble_sort_method
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubble_sort.c
More file actions
39 lines (38 loc) · 673 Bytes
/
bubble_sort.c
File metadata and controls
39 lines (38 loc) · 673 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
39
#include <stdio.h>
#define N 20
int bubble(int n);
int i,j,A[N];
int main()
{
int jml=0;
printf("\t METODE BUBBLE SORT \n\n");
printf("Masukkan jumlah bilangan: ");
scanf("%d",&jml);
printf("\n");
// input data
for (i=0;i<jml;i++){
printf("Bilangan ke %d : ",i+1);
scanf("%d",&A[i]);
}
printf("\n");
// mengurutkan data
bubble(jml);
// menampilkan data
printf("Data yang sudah terurut : \n");
for (i=0;i<jml;i++){
printf("%d\n",A[i]);
}
}
// fungsi bubble
int bubble(int n){
int temp;
for (i=1;i<n;i++){
for (j=i;j<n;j++){
if (A[i-1]>A[j]){ //swapping
temp = A[i-1];
A[i-1] = A[j];
A[j] = temp;
}
}
}
}