mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-02 11:15:19 +08:00
* feat(ko): add the complete Korean online edition * Use UTF-8 for Python CI output on Windows * Remove print-book promotion from the Korean site * fix(ko): preserve emphasis before Korean particles
39 lines
873 B
Kotlin
39 lines
873 B
Kotlin
/**
|
|
* File: queue.kt
|
|
* Created Time: 2024-01-25
|
|
* Author: curtishd ([email protected])
|
|
*/
|
|
|
|
package chapter_stack_and_queue
|
|
|
|
import java.util.*
|
|
|
|
/* 실행 코드 */
|
|
fun main() {
|
|
/* 큐 초기화 */
|
|
val queue = LinkedList<Int>()
|
|
|
|
/* 큐에 원소 삽입 */
|
|
queue.offer(1)
|
|
queue.offer(3)
|
|
queue.offer(2)
|
|
queue.offer(5)
|
|
queue.offer(4)
|
|
println("큐 queue = $queue")
|
|
|
|
/* 맨 앞 원소 접근 */
|
|
val peek = queue.peek()
|
|
println("맨 앞 원소 peek = $peek")
|
|
|
|
/* 큐에서 원소 꺼내기 */
|
|
val pop = queue.poll()
|
|
println("큐에서 꺼낸 원소 pop = $pop, 꺼낸 후 queue = $queue")
|
|
|
|
/* 큐의 길이 반환 */
|
|
val size = queue.size
|
|
println("큐의 길이 size = $size")
|
|
|
|
/* 큐가 비어 있는지 판단 */
|
|
val isEmpty = queue.isEmpty()
|
|
println("큐가 비어 있는가 = $isEmpty")
|
|
} |