mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-13 01:08:11 +08:00
* Retranslate the complete Japanese online edition from Chinese * Fit Japanese homepage labels and localize heading permalinks * Point Japanese contribution instructions to the Japanese preview * Replace locale conditionals with multilingual UI tables
39 lines
945 B
Kotlin
39 lines
945 B
Kotlin
/**
|
|
* File: queue.kt
|
|
* Created Time: 2024-01-25
|
|
* Author: curtishd (1023632660@qq.com)
|
|
*/
|
|
|
|
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")
|
|
} |