Skip to content

Commit 62cd9c7

Browse files
authored
Merge pull request #55 from grap3fruit/soonwon
디렉토리 구조 변경 / doublyLinkedList 구현 / 구름, boj 입력 코드 정리
2 parents 1504ae4 + c9d5882 commit 62cd9c7

77 files changed

Lines changed: 312 additions & 206 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/grap3fruit/goorm/43089.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/grap3fruit/goorm/43125.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/grap3fruit/goorm/88520.js

Lines changed: 0 additions & 64 deletions
This file was deleted.

src/grap3fruit/goorm/input1_2.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/grap3fruit/js/boj/input1_1.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const solution = (N, data) => {
2+
console.log(N);
3+
console.log(data);
4+
};
5+
6+
let fs = require('fs');
7+
let input = fs.readFileSync('test').toString().split('\n');
8+
9+
const N = +input[0];
10+
const data = [];
11+
for (let i = 1; i < N + 1; i++) {
12+
// 위에서 N을 받을떄 input[0]이 빠져나갔기 때문에 1~N을 받아야한다.
13+
data.push(input[i].split(' ').map((el) => +el));
14+
}
15+
16+
solution(N, data);

src/grap3fruit/js/boj/input1_2.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const solution = (N, info, data) => {
2+
console.log(N);
3+
const [X, Y] = info;
4+
console.log(X, Y);
5+
console.log(data);
6+
};
7+
8+
let fs = require('fs');
9+
let input = fs.readFileSync('test2').toString().split('\n');
10+
11+
const N = +input[0];
12+
const info = input[1].split(' ').map((el) => +el);
13+
const data = [];
14+
for (let i = 2; i < N + 2; i++) {
15+
// 위에서 N을 받을떄 input[0]이 빠져나갔기 때문에 1~N을 받아야한다.
16+
data.push(input[i].split(' ').map((el) => +el));
17+
}
18+
19+
solution(N, info, data);

src/grap3fruit/js/boj/test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3
2+
1 2 3
3+
2 3 4
4+
3 4 5

src/grap3fruit/js/boj/test2

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
2 3
3+
1 2 3
4+
2 3 4
5+
3 4 5
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
class Node {
2+
constructor(item) {
3+
this.prev = null;
4+
this.next = null;
5+
this.item = item;
6+
}
7+
}
8+
9+
class DoublyLinkedList {
10+
constructor() {
11+
this.head = new Node(null);
12+
this.tail = new Node(null);
13+
this.head.next = this.tail;
14+
this.tail.prev = this.head;
15+
this.length = 0;
16+
}
17+
18+
getLength() {
19+
return this.length;
20+
}
21+
22+
push(item) {
23+
const node = new Node(item);
24+
this.length += 1;
25+
26+
if (this.head.next === this.tail) {
27+
node.prev = this.head;
28+
node.next = this.tail;
29+
this.head.next = node;
30+
this.tail.prev = node;
31+
return;
32+
}
33+
34+
let lastNode = this.tail.prev;
35+
node.next = this.tail;
36+
node.prev = lastNode;
37+
lastNode.next = node;
38+
this.tail.prev = node;
39+
return;
40+
}
41+
42+
print() {
43+
let current = this.head.next;
44+
while (true) {
45+
if (current === this.tail) {
46+
return;
47+
}
48+
console.log(current.item);
49+
current = current.next;
50+
}
51+
}
52+
53+
pop() {
54+
if (this.length === 0) {
55+
return undefined;
56+
}
57+
this.length -= 1;
58+
const popedNode = this.tail.prev;
59+
popedNode.prev.next = this.tail;
60+
this.tail.prev = popedNode.prev;
61+
return popedNode.item;
62+
}
63+
64+
popLeft() {
65+
if (this.length === 0) {
66+
return undefined;
67+
}
68+
this.length -= 1;
69+
const popedNode = this.head.next;
70+
popedNode.next.prev = this.head;
71+
this.head.next = popedNode.next;
72+
return popedNode.item;
73+
}
74+
75+
filter(callback) {
76+
let current = this.head.next;
77+
const result = [];
78+
while (current !== this.tail) {
79+
console.log(current.item);
80+
if (callback(current.item)) {
81+
result.push(current.item);
82+
}
83+
current = current.next;
84+
}
85+
return result;
86+
}
87+
}
88+
89+
const dl = new DoublyLinkedList();
90+
91+
dl.push([1, 0]);
92+
dl.push([2, 1]);
93+
dl.push([3, 1]);
94+
dl.push([4, 2]);
95+
dl.push([5, 2]);
96+
console.log(dl.filter((el) => el[0] === 1 && el[1] === 0));
97+
console.log('---');
98+
console.log(dl.getLength());
99+
console.log('---');
100+
console.log(dl.popLeft());
101+
console.log('---');
102+
dl.print();
103+
console.log('---');
104+
console.log(dl.pop());
105+
console.log('---');
106+
console.log(dl.getLength());
107+
console.log('---');
108+
dl.print();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const print = (N, data) => {
1+
const solution = (N, data) => {
22
console.log(N);
33
console.log(data);
44
};
@@ -28,6 +28,6 @@ rl.on('line', function (line) {
2828
rl.close();
2929
}
3030
}).on('close', function () {
31-
print(N, data);
31+
solution(N, data);
3232
process.exit();
3333
});

0 commit comments

Comments
 (0)