Add missing Dart codes and fix some errors (#689)

* Add missing Dart codes and fix some errors

* Update array_binary_tree.dart

---------

Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
liuyuxin
2023-08-17 05:04:38 +08:00
committed by GitHub
parent 5d7e0a59b1
commit 0858ab91c0
14 changed files with 504 additions and 204 deletions

View File

@ -44,6 +44,11 @@
1. 下载并安装 [Swift](https://www.swift.org/download/)。
2. 在 VSCode 的插件市场中搜索 `swift` ,安装 [Swift for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=sswg.swift-lang)。
## Dart 环境
1. 下载并安装 [Dart](https://dart.dev/get-dart) 。
2. 在 VSCode 的插件市场中搜索 `dart` ,安装 [Dart](https://marketplace.visualstudio.com/items?itemName=Dart-Code.dart-code) 。
## Rust 环境
1. 下载并安装 [Rust](https://www.rust-lang.org/tools/install)。

View File

@ -48,7 +48,7 @@
Val int // 节点值
Next *ListNode // 指向下一节点的指针(引用)
}
// NewListNode 构造函数,创建一个新的链表
func NewListNode(val int) *ListNode {
return &ListNode{
@ -139,7 +139,7 @@
pub fn ListNode(comptime T: type) type {
return struct {
const Self = @This();
val: T = 0, // 节点值
next: ?*Self = null, // 指向下一节点的指针(引用)
@ -184,7 +184,7 @@
```java title="linked_list.java"
/* 初始化链表 1 -> 3 -> 2 -> 5 -> 4 */
// 初始化各个节点
// 初始化各个节点
ListNode n0 = new ListNode(1);
ListNode n1 = new ListNode(3);
ListNode n2 = new ListNode(2);
@ -201,7 +201,7 @@
```cpp title="linked_list.cpp"
/* 初始化链表 1 -> 3 -> 2 -> 5 -> 4 */
// 初始化各个节点
// 初始化各个节点
ListNode* n0 = new ListNode(1);
ListNode* n1 = new ListNode(3);
ListNode* n2 = new ListNode(2);
@ -218,7 +218,7 @@
```python title="linked_list.py"
# 初始化链表 1 -> 3 -> 2 -> 5 -> 4
# 初始化各个节点
# 初始化各个节点
n0 = ListNode(1)
n1 = ListNode(3)
n2 = ListNode(2)
@ -286,7 +286,7 @@
```c title="linked_list.c"
/* 初始化链表 1 -> 3 -> 2 -> 5 -> 4 */
// 初始化各个节点
// 初始化各个节点
ListNode* n0 = newListNode(1);
ListNode* n1 = newListNode(3);
ListNode* n2 = newListNode(2);
@ -303,7 +303,7 @@
```csharp title="linked_list.cs"
/* 初始化链表 1 -> 3 -> 2 -> 5 -> 4 */
// 初始化各个节点
// 初始化各个节点
ListNode n0 = new ListNode(1);
ListNode n1 = new ListNode(3);
ListNode n2 = new ListNode(2);
@ -337,7 +337,7 @@
```zig title="linked_list.zig"
// 初始化链表
// 初始化各个节点
// 初始化各个节点
var n0 = inc.ListNode(i32){.val = 1};
var n1 = inc.ListNode(i32){.val = 3};
var n2 = inc.ListNode(i32){.val = 2};
@ -747,7 +747,7 @@
Next *DoublyListNode // 指向后继节点的指针(引用)
Prev *DoublyListNode // 指向前驱节点的指针(引用)
}
// NewDoublyListNode 初始化
func NewDoublyListNode(val int) *DoublyListNode {
return &DoublyListNode{
@ -847,7 +847,7 @@
pub fn ListNode(comptime T: type) type {
return struct {
const Self = @This();
val: T = 0, // 节点值
next: ?*Self = null, // 指向后继节点的指针(引用)
prev: ?*Self = null, // 指向前驱节点的指针(引用)
@ -867,10 +867,10 @@
```dart title=""
/* 双向链表节点类 */
class ListNode {
int val; // 节点值
ListNode next; // 指向后继节点的指针(引用)
ListNode prev; // 指向前驱节点的指针(引用)
ListNode(this.val, [this.next, this.prev]); // 构造函数
int val; // 节点值
ListNode next; // 指向后继节点的指针(引用)
ListNode prev; // 指向前驱节点的指针(引用)
ListNode(this.val, [this.next, this.prev]); // 构造函数
}
```
@ -887,7 +887,7 @@
next: Option<Rc<RefCell<ListNode>>>, // 指向后继节点的指针(引用)
prev: Option<Rc<RefCell<ListNode>>>, // 指向前驱节点的指针(引用)
}
/* 构造函数 */
impl ListNode {
fn new(val: i32) -> Self {

View File

@ -168,13 +168,13 @@ index = hash(key) % capacity
=== "Dart"
```dart title="simple_hash.dart"
[class]{}-[func]{add_hash}
[class]{}-[func]{addHash}
[class]{}-[func]{mul_hash}
[class]{}-[func]{mulHash}
[class]{}-[func]{xor_hash}
[class]{}-[func]{xorHash}
[class]{}-[func]{rot_hash}
[class]{}-[func]{rotHash}
```
=== "Rust"
@ -313,7 +313,7 @@ $$
# 布尔量 True 的哈希值为 1
dec = 3.14159
hash_dec = hash(dec)
hash_dec = hash(dec)
# 小数 3.14159 的哈希值为 326484311674566659
str = "Hello 算法"
@ -421,23 +421,23 @@ $$
int num = 3;
int hashNum = num.hashCode;
// 整数 3 的哈希值为 34803
bool bol = true;
int hashBol = bol.hashCode;
// 布尔值 true 的哈希值为 1231
double dec = 3.14159;
int hashDec = dec.hashCode;
// 小数 3.14159 的哈希值为 2570631074981783
String str = "Hello 算法";
int hashStr = str.hashCode;
// 字符串 Hello 算法 的哈希值为 468167534
List arr = [12836, "小哈"];
int hashArr = arr.hashCode;
// 数组 [12836, 小哈] 的哈希值为 976512528
ListNode obj = new ListNode(0);
int hashObj = obj.hashCode;
// 节点对象 Instance of 'ListNode' 的哈希值为 1033450432

View File

@ -16,7 +16,7 @@
!!! tip
当 $k = n$ 时,我们可以得到从大到小的序列,等价于「选择排序」算法。
当 $k = n$ 时,我们可以得到从大到小的序列,等价于「选择排序」算法。
## 方法二:排序
@ -129,7 +129,7 @@
=== "Dart"
```dart title="top_k.dart"
[class]{}-[func]{top_k_heap}
[class]{}-[func]{topKHeap}
```
=== "Rust"