Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
31 lines (25 loc) · 718 Bytes

File metadata and controls

31 lines (25 loc) · 718 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package ch09
import java.util.*
class P23_2 {
// 큐 변수, 구현체는 LinkedList로 선언
val queue: Queue<Int> = LinkedList()
fun push(x: Int) {
// 엘리먼트 삽입
queue.add(x)
// 맨 앞에 두는 상태로 전체 재정렬
for (i in 1 until queue.size)
queue.add(queue.remove())
}
fun pop(): Int {
// 재정렬한 상태이므로 큐 연산으로 추출
return queue.remove()
}
fun top(): Int {
// 재정렬한 상태이므로 큐 연산으로 조회
return queue.peek()
}
fun empty(): Boolean {
// 크기를 비교해 비어있는지 확인
return queue.size == 0
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.