Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- CSS
- 버블정렬
- 코딩테스트
- sort
- 유데미
- JavaScript Deep Dive
- 코드스테이츠 메인프로젝트
- 배열
- next/Image
- primitive type
- 페이지네이션
- Native select
- 이벤트 루프
- kakao map api
- 백준 nodeJS
- input class
- 정규표현식
- 백준
- 코드스테이츠
- 자바스크립트
- 알고리즘
- react js
- nodejs
- 자료구조
- Node js
- javascript
- 프론트엔드
- OSI 7계층
- 재귀함수
- MUI
Archives
- Today
- Total
신입 개발자에서 시니어 개발자가 되기까지
[백준] 2750번 오름차순 정렬(node.js) 본문
오름차순 정렬. 혹시나해서 기본 내장 메서드로 풀어봤는데 틀리길래 버블정렬로 풀었다.
const notSorted = require("fs")
.readFileSync("/dev/stdin")
.toString()
.trim()
.split("\n");
let arr = notSorted.splice(1).map(Number);
function swap(array, idx1, idx2) {
[array[idx1], array[idx2]] = [array[idx2], array[idx1]];
}
for (let i = 0; i < arr.length; i++) {
for (let j = arr.length - 1; j > i; j--) {
if (arr[j] < arr[j - 1]) {
swap(arr, j, j - 1);
}
}
}
console.log(arr.join("\n"));
'javascript > 알고리즘' 카테고리의 다른 글
[백준 node JS] 정렬 2108 통계학 (0) | 2022.10.07 |
---|---|
[백준 node JS] 25305 커트라인 (0) | 2022.10.06 |
[백준 node js] 25501 재귀함수 Palindrome (0) | 2022.09.19 |
기본수학2 9020 - 골드바흐의 추측 (0) | 2022.08.22 |
백준 javascript 재귀함수 10872 - 팩토리얼 (0) | 2022.08.22 |