-
Notifications
You must be signed in to change notification settings - Fork 0
/
문제02_10845_큐.kt
48 lines (42 loc) · 1.12 KB
/
문제02_10845_큐.kt
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package ryute.topic01.sub02
import java.io.BufferedWriter
import java.io.OutputStreamWriter
import java.util.*
private fun main() {
solution01()
}
/*** 정답 코드 ***/
private fun solution01() {
val linkedList = LinkedList<Int>()
val bw = BufferedWriter(OutputStreamWriter(System.out))
val n = readLine()!!.toInt()
repeat(n) {
val command = readLine()!!.split(" ")
when(command[0]) {
"push" -> {
linkedList.add(command[1].toInt())
}
"pop" -> {
bw.write("${linkedList.pollFirst()?:-1}\n")
}
"size" -> {
bw.write("${linkedList.size}\n")
}
"empty" -> {
if(linkedList.isEmpty()) {
bw.write("1\n")
} else {
bw.write("0\n")
}
}
"front" -> {
bw.write("${linkedList.peekFirst()?:-1}\n")
}
"back" -> {
bw.write("${linkedList.peekLast()?:-1}\n")
}
}
}
bw.flush()
bw.close()
}