We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0627441 commit 6d489cbCopy full SHA for 6d489cb
yoonexample/src/main/java/sort/InsertionSort.java
@@ -0,0 +1,25 @@
1
+package sort;
2
+
3
+public class InsertionSort implements Sort {
4
5
+ @Override
6
+ public void sort(int[] array) {
7
+ int length = array.length;
8
+ int insertData;
9
10
+ for (int i = 1; i < length; i++) {
11
+ insertData = array[i];
12
+ int j;
13
14
+ for (j = i - 1; j >= 0; j--) { // 정렬된 배열의 뒷부분 부터 비교해서 삽입위치 탐색
15
+ if (array[j] > insertData) { // 삽입할 데이터가 작으면
16
+ array[j + 1] = array[j]; // 위치 변경
17
+ } else {
18
+ break; // 해당 위치에 삽입되어야 하므로 탈출
19
+ }
20
21
22
+ array[j + 1] = insertData;
23
24
25
+}
0 commit comments