// KISS 원칙
// Keep It Simple Stupid : 단순무식하게 유지해라
// DRY 원칙
// Don't Repeat Yourself : 중복 코드를 제거하여 효율적으로 작성해라
// YAGNI 원칙
// You Aren't Gonna Need It : 지금 필요하지 않은 건 만들지 마라
public static void InsertionSort(int[] arr)
{
int n = arr.Length;
for (int i = 1; i < n; i++)
{
int key = arr[i];
int j = i - 1;
while (j >= 0 && arr[j] > key)
{
arr[j + 1] = arr[j];
j--;
}
arr[j + 1] = key;
}
}
// 삽입 정렬
// Insertion Sort
// 정렬되지 않은 데이터를 하나씩 꺼냄
// 정렬된 부분에 알맞은 위치에 삽입하는 방식의 정렬
public static void InsertionSort(int[] arr)
{
int n = arr.Length;
for (int i = 1; i < n; i++)
{
int key = arr[i];
int j = i - 1;
while (j >= 0 && arr[j] > key)
{
arr[j + 1] = arr[j];
j--;
}
arr[j + 1] = key;
}
}
'📖TIL' 카테고리의 다른 글
| 250929 (0) | 2025.09.29 |
|---|---|
| 250929 Revision (0) | 2025.09.29 |
| 250926 알고리즘 (0) | 2025.09.26 |
| 250926 Revision (0) | 2025.09.26 |
| 250925 (0) | 2025.09.25 |