forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path3.java
30 lines (24 loc) Β· 822 Bytes
/
3.java
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
import java.util.*;
public class Main {
public static void main(String[] args) {
int n = 10;
int[] arr = {7, 5, 9, 0, 3, 1, 6, 2, 4, 8};
for (int i = 1; i < n; i++) {
// μΈλ±μ€ iλΆν° 1κΉμ§ κ°μνλ©° λ°λ³΅νλ λ¬Έλ²
for (int j = i; j > 0; j--) {
// ν μΉΈμ© μΌμͺ½μΌλ‘ μ΄λ
if (arr[j] < arr[j - 1]) {
// μ€μν(Swap)
int temp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = temp;
}
// μκΈ°λ³΄λ€ μμ λ°μ΄ν°λ₯Ό λ§λλ©΄ κ·Έ μμΉμμ λ©μΆ€
else break;
}
}
for(int i = 0; i < n; i++) {
System.out.print(arr[i] + " ");
}
}
}