mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-14 16:16:06 +00:00
feat: modify some Dart codes and add Dart code blocks to the docs (#543)
This commit is contained in:
@@ -156,7 +156,12 @@
|
||||
=== "Dart"
|
||||
|
||||
```dart title=""
|
||||
|
||||
/* 链表节点类 */
|
||||
class ListNode {
|
||||
int val; // 节点值
|
||||
ListNode? next; // 指向下一节点的指针(引用)
|
||||
ListNode(this.val, [this.next]); // 构造函数
|
||||
}
|
||||
```
|
||||
|
||||
!!! question "尾节点指向什么?"
|
||||
@@ -342,7 +347,18 @@
|
||||
=== "Dart"
|
||||
|
||||
```dart title="linked_list.dart"
|
||||
|
||||
/* 初始化链表 1 -> 3 -> 2 -> 5 -> 4 */\
|
||||
// 初始化各个节点
|
||||
ListNode n0 = ListNode(1);
|
||||
ListNode n1 = ListNode(3);
|
||||
ListNode n2 = ListNode(2);
|
||||
ListNode n3 = ListNode(5);
|
||||
ListNode n4 = ListNode(4);
|
||||
// 构建引用指向
|
||||
n0.next = n1;
|
||||
n1.next = n2;
|
||||
n2.next = n3;
|
||||
n3.next = n4;
|
||||
```
|
||||
|
||||
## 链表优点
|
||||
@@ -799,7 +815,13 @@
|
||||
=== "Dart"
|
||||
|
||||
```dart title=""
|
||||
|
||||
/* 双向链表节点类 */
|
||||
class ListNode {
|
||||
int val; // 节点值
|
||||
ListNode next; // 指向后继节点的指针(引用)
|
||||
ListNode prev; // 指向前驱节点的指针(引用)
|
||||
ListNode(this.val, [this.next, this.prev]); // 构造函数
|
||||
}
|
||||
```
|
||||
|
||||

|
||||
|
||||
Reference in New Issue
Block a user