mirror of
https://github.com/krahets/hello-algo.git
synced 2026-02-03 02:43:41 +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:
@@ -299,7 +299,27 @@
|
||||
=== "Kotlin"
|
||||
|
||||
```kotlin title="stack.kt"
|
||||
|
||||
/* 初始化栈 */
|
||||
val stack = Stack<Int>()
|
||||
|
||||
/* 元素入栈 */
|
||||
stack.push(1)
|
||||
stack.push(3)
|
||||
stack.push(2)
|
||||
stack.push(5)
|
||||
stack.push(4)
|
||||
|
||||
/* 访问栈顶元素 */
|
||||
val peek = stack.peek()
|
||||
|
||||
/* 元素出栈 */
|
||||
val pop = stack.pop()
|
||||
|
||||
/* 获取栈的长度 */
|
||||
val size = stack.size
|
||||
|
||||
/* 判断是否为空 */
|
||||
val isEmpty = stack.isEmpty()
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
Reference in New Issue
Block a user