-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort_bubble_2dimensi2.cpp
More file actions
60 lines (54 loc) · 978 Bytes
/
sort_bubble_2dimensi2.cpp
File metadata and controls
60 lines (54 loc) · 978 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "stdio.h"
int main()
{
int A[4][6] = {10,7,15,4,9,10,
15,20,18,15,20,25,
12,6,7,4,11,18,
5,8,11,16,9,2};
int B[24] = {0};
int I, J, K, X;
//1. cetak A (sebelum sorting)
for(I=0; I<4; I++) {
for(J=0; J<6; J++) {
printf("%4i", A[I][J]);
}
printf("\n");
}
//2. ubah array A menjadi 1 dimensi
K=0;
for(I=0; I<4; I++) {
for(J=0; J<6; J++) {
B[K] = A[I][J];
K++;
}
}
for(I=0; I<24;I++) {
printf("%4i", B[I]);
}
//3. sorting array B
for(I=0; I<(24-1); I++) {
for(J=0; J<24-I; J++) {
if(B[J] > B[J+1]) {
X = B[J];
B[J] = B[J+1];
B[J+1] = X;
}
}
}
//4. ubah array B menjadi 2 dimensi (array A)
K = 0;
for(I=0; I<4; I++) {
for(J=0; J<6; J++) {
A[I][J] = B[K];
K++;
}
}
printf("\n\n");
//5. cetak A (setelah sorting)
for(I=0; I<4; I++) {
for(J=0; J<6; J++) {
printf("%4i", A[I][J]);
}
printf("\n");
}
}