mirror of
https://github.com/krahets/hello-algo.git
synced 2026-02-03 10:53:35 +08:00
Add kotlin code for chapter_stack_and_queue and chapter_tree (#1197)
* Add kotlin code block for chapter_hashing * Add kotlin code block for chapter_heap. * Add kotlin code block for chapter_stack_and_queue and chapter_tree * fix indentation * Update binary_tree.md --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
@@ -305,7 +305,27 @@
|
||||
=== "Kotlin"
|
||||
|
||||
```kotlin title="queue.kt"
|
||||
|
||||
/* 初始化队列 */
|
||||
val queue = LinkedList<Int>()
|
||||
|
||||
/* 元素入队 */
|
||||
queue.offer(1)
|
||||
queue.offer(3)
|
||||
queue.offer(2)
|
||||
queue.offer(5)
|
||||
queue.offer(4)
|
||||
|
||||
/* 访问队首元素 */
|
||||
val peek = queue.peek()
|
||||
|
||||
/* 元素出队 */
|
||||
val pop = queue.poll()
|
||||
|
||||
/* 获取队列的长度 */
|
||||
val size = queue.size
|
||||
|
||||
/* 判断队列是否为空 */
|
||||
val isEmpty = queue.isEmpty()
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
Reference in New Issue
Block a user