✅Notion: Hyunsb_InsertionSort
public int[] InsertionSort(int[] arr){
for(int i=1; i<arr.length; i++){
int temp = arr[i];
int prev;
for(prev=i-1; prev>=0; prev--){
if(temp < arr[prev])
arr[prev+1] = arr[prev];
else break;
}
arr[prev+1] = temp;
}
return arr;
}
✅Notion: Hyunsb_InsertionSort
삽입 정렬 (Insertion Sort)
배열의 모든 요소를 앞에서부터 차례대로 “이미 정렬된 배열 부분과 비교”하여, 자신의 위치를 찾아 삽입함으로써 정렬을 완성하는 알고리즘이다.
cyclic-comfort-69d.notion.site
'알고리즘' 카테고리의 다른 글
[Searching] 결정 알고리즘 (Decision Algorithm) (0) | 2022.12.02 |
---|---|
[Searching] 이분 검색 (Binary Search) (0) | 2022.12.02 |
[Sorting and Searching] 버블 정렬 (Bubble Sort) (0) | 2022.11.24 |
[Sorting and Searching] 선택 정렬 (Selection Sort) (0) | 2022.11.24 |