2752번: 세수 정렬
마지막 업데이트
let fs = require('fs');
const filePath = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
let input = fs.readFileSync(filePath).toString().trim().split(' ').map(Number);
console.log(input.sort((a, b) => a - b).join(' '))let fs = require('fs');
const input = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
let arr = input[0].split(' ').map(Number);
arr.sort(function (a, b) {
return a - b;
});
let answer = ''
for (let i = 0; i < arr.length; i++) {
answer += arr[i] + ' ';
}
console.log(answer);// 선택 정렬 사용
function selectionSort(arr) {
for (let i = 0; i < arr.length - 1; i++) {
let minIndex = i;
for (let j = i + 1; j < arr.length; j++) {
if (arr[j] < arr[minIndex]) {
minIndex = j;
}
let temp = arr[i]
arr[i] = arr[minIndex]
arr[minIndex] = temp
}
}
}
let fs = require('fs');
const input = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
let arr = input[0].split(' ').map(Number);
selectionSort(arr);
let answer = ''
for (let i = 0; i < arr.length; i++) {
answer += arr[i] + ' ';
}
console.log(answer);