mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-28 12:52:57 +08:00
build
This commit is contained in:
@ -125,7 +125,7 @@ comments: true
|
||||
```kotlin title=""
|
||||
/* 二元樹的陣列表示 */
|
||||
// 使用 null 來表示空位
|
||||
val tree = mutableListOf( 1, 2, 3, 4, null, 6, 7, 8, 9, null, null, 12, null, null, 15 )
|
||||
val tree = arrayOf( 1, 2, 3, 4, null, 6, 7, 8, 9, null, null, 12, null, null, 15 )
|
||||
```
|
||||
|
||||
=== "Ruby"
|
||||
@ -1172,7 +1172,7 @@ comments: true
|
||||
=== "Kotlin"
|
||||
|
||||
```kotlin title="array_binary_tree.kt"
|
||||
/* 建構子 */
|
||||
/* 陣列表示下的二元樹類別 */
|
||||
class ArrayBinaryTree(val tree: MutableList<Int?>) {
|
||||
/* 串列容量 */
|
||||
fun size(): Int {
|
||||
|
@ -305,7 +305,7 @@ comments: true
|
||||
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