Insertion Sort

    Algorithm / 정렬 / Insertion Sort (삽입 정렬)

    삽입 정렬 function insertion_sort(arr) { console.log(`Before insertion sorting: ${[...arr]}`); let cnt = 0; for (var i = 1; i = 0 && arr[j] > cur; j--) { if (cur < arr[j]) arr[j + 1] = arr[j]; cnt++; } arr[j + 1] = cur; } console.log(`After insertion sorting: ${[...arr]}`); console.log(`Sorting count = ${cnt}`); } let arr = [3, 6, 13, 4..