http://way2java.com |
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
|
public class TestASCArraySort {
public static void main(String[] args) {
int[] point = { 4, 2, 3, 1 };
System.out.println("정렬전");
showArray(point);
System.out.println();
// 정렬작업
int size = point.length;
for (int i = 0; i < size; i++) {
for (int j = i + 1; j < size; j++) {
if (point[i] > point[j]) {
int temp = point[i];// 교환(swap)
point[i] = point[j];
point[j] = temp;
}
System.out.println(i + " " + j + " 요소 비교해 i가 j보다 크면 교환");
showArray(point);
System.out.println();
}
}
System.out.println();
System.out.println("정렬 후");
showArray(point);
}
public static void showArray(int[] p) {
for (int i = 0; i < p.length; i++) {
System.out.print(p[i] + " ");
}
}
}
| cs |
0 개의 댓글:
댓글 쓰기