mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-30 05:43:10 +08:00
build
This commit is contained in:
@ -1172,7 +1172,7 @@ The following code implements a binary tree based on array representation, inclu
|
||||
=== "Kotlin"
|
||||
|
||||
```kotlin title="array_binary_tree.kt"
|
||||
/* 构造方法 */
|
||||
/* 数组表示下的二叉树类 */
|
||||
class ArrayBinaryTree(val tree: MutableList<Int?>) {
|
||||
/* 列表容量 */
|
||||
fun size(): Int {
|
||||
|
@ -305,7 +305,7 @@ Breadth-first traversal is usually implemented with the help of a "queue". The q
|
||||
val list = mutableListOf<Int>()
|
||||
while (queue.isNotEmpty()) {
|
||||
val node = queue.poll() // 队列出队
|
||||
list.add(node?._val!!) // 保存节点值
|
||||
list.add(node?._val!!) // 保存节点值
|
||||
if (node.left != null)
|
||||
queue.offer(node.left) // 左子节点入队
|
||||
if (node.right != null)
|
||||
|
Reference in New Issue
Block a user