선택 정렬

    Algorithm / 정렬 / Selection Sort (선택 정렬)

    Selection Sort (선택 정렬) function selection_sort1(arr) { console.log(`before selection sorting: ${[...arr]}`); let cnt = 0; for (let i = 0; i < arr.length; i++) { let smaller_idx = i; for (let j = i + 1; j < arr.length; j++) { if (arr[j] < arr[smaller_idx]) { smaller_idx = j; } } // swap [arr[i], arr[smaller_idx]] = [arr[smaller_idx], arr[i]]; cnt++; } console.log(`after selection sorting: ${[...a..