Add kotlin code block for chapter array and linkedlist (#1179)

* add kotlin code block for chapter_array_and_linkedlist.

* modified comment.

* Update list.md

* Update linked_list.md

* fix some indentation.

* fix incorrect display
This commit is contained in:
curtishd
2024-03-27 01:12:30 +08:00
committed by GitHub
parent 1c8359129f
commit 82a7dc9dcc
2 changed files with 63 additions and 7 deletions
@@ -162,7 +162,12 @@
=== "Kotlin"
```kotlin title=""
/* 链表节点类 */
// 构造方法
class ListNode(x: Int) {
val `val`: Int = x // 节点值
val next: ListNode? = null // 指向下一个节点的引用
}
```
=== "Zig"
@@ -382,7 +387,18 @@
=== "Kotlin"
```kotlin title="linked_list.kt"
/* 初始化链表 1 -> 3 -> 2 -> 5 -> 4 */
// 初始化各个节点
val n0 = ListNode(1)
val n1 = ListNode(3)
val n2 = ListNode(2)
val n3 = ListNode(5)
val n4 = ListNode(4)
// 构建节点之间的引用
n0.next = n1;
n1.next = n2;
n2.next = n3;
n3.next = n4;
```
=== "Zig"
@@ -643,7 +659,13 @@
=== "Kotlin"
```kotlin title=""
/* 双向链表节点类 */
// 构造方法
class ListNode(x: Int) {
val `val`: Int = x // 节点值
val next: ListNode? = null // 指向后继节点的引用
val prev: ListNode? = null // 指向前驱节点的引用
}
```
=== "Zig"