Fix compile errors in doc code snippets (#2033)

Seventeen snippet blocks in codes/snippets did not compile or did something other than
what their comments say. Each fix is the smallest change that makes the snippet valid,
and follows the matching demo code where one exists:

- space_complexity: Java and C `if` bodies get braces; C drops the initializer on a
  variable-length array; Go assigns instead of shadowing `nums`; Rust renames the
  `loop` function (a keyword) to `for_loop`; Dart makes `Node.next` nullable.
- time_complexity: Ruby `.each do { ... }` becomes `.each { ... }`.
- basic_data_types: Ruby `ListNode(0)` becomes `ListNode.new(0)`.
- heap: C++ assigns `minHeap` instead of declaring it twice.
- hash_map: Dart reads into `String?`; Rust uses key 13276 like the other languages.
- list: Rust `nums` is `mut`; Kotlin removes index 3 with `removeAt(3)`.
- linked_list: C# node fields are public and nullable; a stray `\` after a Dart
  comment is removed.
- backtracking_algorithm: Python `list[Choice]`/`list[State]`, C++ `Choice *choice`,
  Dart `List<Choice> choices`.

All six editions change identically; zh-hant is regenerated by OpenCC. Comments are
unchanged.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Yudong Jin
2026-11-16 02:35:29 +08:00
committed by GitHub
parent 3d53548b80
commit 8c96e2f30c
48 changed files with 156 additions and 144 deletions

View File

@@ -28,8 +28,8 @@ class ListNode {
```csharp title="" ```csharp title=""
/* 链表节点类 */ /* 链表节点类 */
class ListNode(int x) { //构造函数 class ListNode(int x) { //构造函数
int val = x; // 节点值 public int val = x; // 节点值
ListNode? next; // 指向下一节点的引用 public ListNode? next; // 指向下一节点的引用
} }
``` ```
@@ -264,7 +264,7 @@ n3.next = n4;
``` ```
```dart title="linked_list.dart" ```dart title="linked_list.dart"
/* 初始化链表 1 -> 3 -> 2 -> 5 -> 4 */\ /* 初始化链表 1 -> 3 -> 2 -> 5 -> 4 */
// 初始化各个节点 // 初始化各个节点
ListNode n0 = ListNode(1); ListNode n0 = ListNode(1);
ListNode n1 = ListNode(3); ListNode n1 = ListNode(3);
@@ -375,9 +375,9 @@ class ListNode {
```csharp title="" ```csharp title=""
/* 双向链表节点类 */ /* 双向链表节点类 */
class ListNode(int x) { // 构造函数 class ListNode(int x) { // 构造函数
int val = x; // 节点值 public int val = x; // 节点值
ListNode next; // 指向后继节点的引用 public ListNode? next; // 指向后继节点的引用
ListNode prev; // 指向前驱节点的引用 public ListNode? prev; // 指向前驱节点的引用
} }
``` ```

View File

@@ -79,7 +79,7 @@ List<int> nums = [1, 3, 2, 5, 4];
// 无初始值 // 无初始值
let nums1: Vec<i32> = Vec::new(); let nums1: Vec<i32> = Vec::new();
// 有初始值 // 有初始值
let nums: Vec<i32> = vec![1, 3, 2, 5, 4]; let mut nums: Vec<i32> = vec![1, 3, 2, 5, 4];
``` ```
```c title="list.c" ```c title="list.c"
@@ -404,10 +404,10 @@ nums.add(5);
nums.add(4); nums.add(4);
/* 在中间插入元素 */ /* 在中间插入元素 */
nums.add(3, 6); // 在索引 3 处插入数字 6 nums.add(3, 6); // 在索引 3 处插入数字 6
/* 删除元素 */ /* 删除元素 */
nums.remove(3); // 删除索引 3 处的元素 nums.removeAt(3); // 删除索引 3 处的元素
``` ```
```ruby title="list.rb" ```ruby title="list.rb"

View File

@@ -1,6 +1,6 @@
<!-- [snippet]{backtrack_framework} --> <!-- [snippet]{backtrack_framework} -->
```python title="" ```python title=""
def backtrack(state: State, choices: list[choice], res: list[state]): def backtrack(state: State, choices: list[Choice], res: list[State]):
"""回溯算法框架""" """回溯算法框架"""
# 判断是否为解 # 判断是否为解
if is_solution(state): if is_solution(state):
@@ -30,7 +30,7 @@ void backtrack(State *state, vector<Choice *> &choices, vector<State *> &res) {
return; return;
} }
// 遍历所有选择 // 遍历所有选择
for (Choice choice : choices) { for (Choice *choice : choices) {
// 剪枝:判断选择是否合法 // 剪枝:判断选择是否合法
if (isValid(state, choice)) { if (isValid(state, choice)) {
// 尝试:做出选择,更新状态 // 尝试:做出选择,更新状态
@@ -189,7 +189,7 @@ function backtrack(state: State, choices: Choice[], res: State[]): void {
```dart title="" ```dart title=""
/* 回溯算法框架 */ /* 回溯算法框架 */
void backtrack(State state, List<Choice>, List<State> res) { void backtrack(State state, List<Choice> choices, List<State> res) {
// 判断是否为解 // 判断是否为解
if (isSolution(state)) { if (isSolution(state)) {
// 记录解 // 记录解

View File

@@ -196,7 +196,7 @@ function algorithm(n: number): number { // 输入数据
/* 类 */ /* 类 */
class Node { class Node {
int val; int val;
Node next; Node? next;
Node(this.val, [this.next]); Node(this.val, [this.next]);
} }
@@ -332,8 +332,9 @@ void algorithm(int n) {
void algorithm(int n) { void algorithm(int n) {
int a = 0; // O(1) int a = 0; // O(1)
int[] b = new int[10000]; // O(1) int[] b = new int[10000]; // O(1)
if (n > 10) if (n > 10) {
int[] nums = new int[n]; // O(n) int[] nums = new int[n]; // O(n)
}
} }
``` ```
@@ -353,7 +354,7 @@ func algorithm(n int) {
b := make([]int, 10000) // O(1) b := make([]int, 10000) // O(1)
var nums []int var nums []int
if n > 10 { if n > 10 {
nums := make([]int, n) // O(n) nums = make([]int, n) // O(n)
} }
fmt.Println(a, b, nums) fmt.Println(a, b, nums)
} }
@@ -413,8 +414,9 @@ fn algorithm(n: i32) {
void algorithm(int n) { void algorithm(int n) {
int a = 0; // O(1) int a = 0; // O(1)
int b[10000]; // O(1) int b[10000]; // O(1)
if (n > 10) if (n > 10) {
int nums[n] = {0}; // O(n) int nums[n]; // O(n)
}
} }
``` ```
@@ -613,7 +615,7 @@ fn function() -> i32 {
return 0; return 0;
} }
/* 循环的空间复杂度为 O(1) */ /* 循环的空间复杂度为 O(1) */
fn loop(n: i32) { fn for_loop(n: i32) {
for i in 0..n { for i in 0..n {
function(); function();
} }

View File

@@ -774,10 +774,10 @@ def algorithm(n)
a = 1 # +0(技巧 1) a = 1 # +0(技巧 1)
a = a + n # +0(技巧 1) a = a + n # +0(技巧 1)
# +n(技巧 2) # +n(技巧 2)
(0...(5 * n + 1)).each do { puts 0 } (0...(5 * n + 1)).each { puts 0 }
# +n*n(技巧 3) # +n*n(技巧 3)
(0...(2 * n)).each do (0...(2 * n)).each do
(0...(n + 1)).each do { puts 0 } (0...(n + 1)).each { puts 0 }
end end
end end
``` ```

View File

@@ -96,7 +96,7 @@ val bools = BooleanArray(5)
```ruby title="" ```ruby title=""
# Ruby 的列表可以自由存储各种基本数据类型和对象引用 # Ruby 的列表可以自由存储各种基本数据类型和对象引用
data = [0, 0.0, 'a', false, ListNode(0)] data = [0, 0.0, 'a', false, ListNode.new(0)]
``` ```
<!-- [tutor]{basic_type_arrays_tutor} --> <!-- [tutor]{basic_type_arrays_tutor} -->

View File

@@ -184,7 +184,7 @@ map[10583] = "小鸭";
/* 查询操作 */ /* 查询操作 */
// 向哈希表中输入键 key ,得到值 value // 向哈希表中输入键 key ,得到值 value
String name = map[15937]; String? name = map[15937];
/* 删除操作 */ /* 删除操作 */
// 在哈希表中删除键值对 (key, value) // 在哈希表中删除键值对 (key, value)
@@ -202,7 +202,7 @@ let mut map: HashMap<i32, String> = HashMap::new();
map.insert(12836, "小哈".to_string()); map.insert(12836, "小哈".to_string());
map.insert(15937, "小啰".to_string()); map.insert(15937, "小啰".to_string());
map.insert(16750, "小算".to_string()); map.insert(16750, "小算".to_string());
map.insert(13279, "小法".to_string()); map.insert(13276, "小法".to_string());
map.insert(10583, "小鸭".to_string()); map.insert(10583, "小鸭".to_string());
/* 查询操作 */ /* 查询操作 */

View File

@@ -71,7 +71,7 @@ bool isEmpty = maxHeap.empty();
/* 输入列表并建堆 */ /* 输入列表并建堆 */
vector<int> input{1, 3, 2, 5, 4}; vector<int> input{1, 3, 2, 5, 4};
priority_queue<int, vector<int>, greater<int>> minHeap(input.begin(), input.end()); minHeap = priority_queue<int, vector<int>, greater<int>>(input.begin(), input.end());
``` ```
```java title="heap.java" ```java title="heap.java"

View File

@@ -28,8 +28,8 @@ class ListNode {
```csharp title="" ```csharp title=""
/* Linked list node class */ /* Linked list node class */
class ListNode(int x) { // Constructor class ListNode(int x) { // Constructor
int val = x; // Node value public int val = x; // Node value
ListNode? next; // Reference to the next node public ListNode? next; // Reference to the next node
} }
``` ```
@@ -264,7 +264,7 @@ n3.next = n4;
``` ```
```dart title="linked_list.dart" ```dart title="linked_list.dart"
/* Initialize the linked list 1 -> 3 -> 2 -> 5 -> 4 */\ /* Initialize the linked list 1 -> 3 -> 2 -> 5 -> 4 */
// Initialize the nodes // Initialize the nodes
ListNode n0 = ListNode(1); ListNode n0 = ListNode(1);
ListNode n1 = ListNode(3); ListNode n1 = ListNode(3);
@@ -375,9 +375,9 @@ class ListNode {
```csharp title="" ```csharp title=""
/* Doubly linked list node class */ /* Doubly linked list node class */
class ListNode(int x) { // Constructor class ListNode(int x) { // Constructor
int val = x; // Node value public int val = x; // Node value
ListNode next; // Reference to the successor public ListNode? next; // Reference to the successor
ListNode prev; // Reference to the predecessor public ListNode? prev; // Reference to the predecessor
} }
``` ```

View File

@@ -79,7 +79,7 @@ List<int> nums = [1, 3, 2, 5, 4];
// Without initial values // Without initial values
let nums1: Vec<i32> = Vec::new(); let nums1: Vec<i32> = Vec::new();
// With initial values // With initial values
let nums: Vec<i32> = vec![1, 3, 2, 5, 4]; let mut nums: Vec<i32> = vec![1, 3, 2, 5, 4];
``` ```
```c title="list.c" ```c title="list.c"
@@ -404,10 +404,10 @@ nums.add(5);
nums.add(4); nums.add(4);
/* Insert an element in the middle */ /* Insert an element in the middle */
nums.add(3, 6); // Insert 6 at index 3 nums.add(3, 6); // Insert 6 at index 3
/* Remove an element */ /* Remove an element */
nums.remove(3); // Remove the element at index 3 nums.removeAt(3); // Remove the element at index 3
``` ```
```ruby title="list.rb" ```ruby title="list.rb"

View File

@@ -1,6 +1,6 @@
<!-- [snippet]{backtrack_framework} --> <!-- [snippet]{backtrack_framework} -->
```python title="" ```python title=""
def backtrack(state: State, choices: list[choice], res: list[state]): def backtrack(state: State, choices: list[Choice], res: list[State]):
"""Backtracking template""" """Backtracking template"""
# Check whether the state is a solution # Check whether the state is a solution
if is_solution(state): if is_solution(state):
@@ -30,7 +30,7 @@ void backtrack(State *state, vector<Choice *> &choices, vector<State *> &res) {
return; return;
} }
// Try every choice // Try every choice
for (Choice choice : choices) { for (Choice *choice : choices) {
// Prune: check whether the choice is valid // Prune: check whether the choice is valid
if (isValid(state, choice)) { if (isValid(state, choice)) {
// Try: make the choice and update the state // Try: make the choice and update the state
@@ -189,7 +189,7 @@ function backtrack(state: State, choices: Choice[], res: State[]): void {
```dart title="" ```dart title=""
/* Backtracking template */ /* Backtracking template */
void backtrack(State state, List<Choice>, List<State> res) { void backtrack(State state, List<Choice> choices, List<State> res) {
// Check whether the state is a solution // Check whether the state is a solution
if (isSolution(state)) { if (isSolution(state)) {
// Record the solution // Record the solution

View File

@@ -196,7 +196,7 @@ function algorithm(n: number): number { // Input data
/* Class */ /* Class */
class Node { class Node {
int val; int val;
Node next; Node? next;
Node(this.val, [this.next]); Node(this.val, [this.next]);
} }
@@ -332,8 +332,9 @@ void algorithm(int n) {
void algorithm(int n) { void algorithm(int n) {
int a = 0; // O(1) int a = 0; // O(1)
int[] b = new int[10000]; // O(1) int[] b = new int[10000]; // O(1)
if (n > 10) if (n > 10) {
int[] nums = new int[n]; // O(n) int[] nums = new int[n]; // O(n)
}
} }
``` ```
@@ -353,7 +354,7 @@ func algorithm(n int) {
b := make([]int, 10000) // O(1) b := make([]int, 10000) // O(1)
var nums []int var nums []int
if n > 10 { if n > 10 {
nums := make([]int, n) // O(n) nums = make([]int, n) // O(n)
} }
fmt.Println(a, b, nums) fmt.Println(a, b, nums)
} }
@@ -413,8 +414,9 @@ fn algorithm(n: i32) {
void algorithm(int n) { void algorithm(int n) {
int a = 0; // O(1) int a = 0; // O(1)
int b[10000]; // O(1) int b[10000]; // O(1)
if (n > 10) if (n > 10) {
int nums[n] = {0}; // O(n) int nums[n]; // O(n)
}
} }
``` ```
@@ -613,7 +615,7 @@ fn function() -> i32 {
return 0; return 0;
} }
/* The loop uses O(1) space */ /* The loop uses O(1) space */
fn loop(n: i32) { fn for_loop(n: i32) {
for i in 0..n { for i in 0..n {
function(); function();
} }

View File

@@ -774,10 +774,10 @@ def algorithm(n)
a = 1 # +0 (shortcut 1) a = 1 # +0 (shortcut 1)
a = a + n # +0 (shortcut 1) a = a + n # +0 (shortcut 1)
# +n (shortcut 2) # +n (shortcut 2)
(0...(5 * n + 1)).each do { puts 0 } (0...(5 * n + 1)).each { puts 0 }
# +n*n (shortcut 3) # +n*n (shortcut 3)
(0...(2 * n)).each do (0...(2 * n)).each do
(0...(n + 1)).each do { puts 0 } (0...(n + 1)).each { puts 0 }
end end
end end
``` ```

View File

@@ -96,7 +96,7 @@ val bools = BooleanArray(5)
```ruby title="" ```ruby title=""
# Ruby arrays can hold different basic data types and object references # Ruby arrays can hold different basic data types and object references
data = [0, 0.0, 'a', false, ListNode(0)] data = [0, 0.0, 'a', false, ListNode.new(0)]
``` ```
<!-- [tutor]{basic_type_arrays_tutor} --> <!-- [tutor]{basic_type_arrays_tutor} -->

View File

@@ -184,7 +184,7 @@ map[10583] = "小鸭";
/* Lookup */ /* Lookup */
// Look up key in the hash table to obtain value // Look up key in the hash table to obtain value
String name = map[15937]; String? name = map[15937];
/* Deletion */ /* Deletion */
// Remove a key-value pair (key, value) from the hash table // Remove a key-value pair (key, value) from the hash table
@@ -202,7 +202,7 @@ let mut map: HashMap<i32, String> = HashMap::new();
map.insert(12836, "小哈".to_string()); map.insert(12836, "小哈".to_string());
map.insert(15937, "小啰".to_string()); map.insert(15937, "小啰".to_string());
map.insert(16750, "小算".to_string()); map.insert(16750, "小算".to_string());
map.insert(13279, "小法".to_string()); map.insert(13276, "小法".to_string());
map.insert(10583, "小鸭".to_string()); map.insert(10583, "小鸭".to_string());
/* Lookup */ /* Lookup */

View File

@@ -71,7 +71,7 @@ bool isEmpty = maxHeap.empty();
/* Build a heap from a list */ /* Build a heap from a list */
vector<int> input{1, 3, 2, 5, 4}; vector<int> input{1, 3, 2, 5, 4};
priority_queue<int, vector<int>, greater<int>> minHeap(input.begin(), input.end()); minHeap = priority_queue<int, vector<int>, greater<int>>(input.begin(), input.end());
``` ```
```java title="heap.java" ```java title="heap.java"

View File

@@ -28,8 +28,8 @@ class ListNode {
```csharp title="" ```csharp title=""
/* 連結リストのノードクラス */ /* 連結リストのノードクラス */
class ListNode(int x) { //コンストラクタ class ListNode(int x) { //コンストラクタ
int val = x; // ノードの値 public int val = x; // ノードの値
ListNode? next; // 次のノードへの参照 public ListNode? next; // 次のノードへの参照
} }
``` ```
@@ -264,7 +264,7 @@ n3.next = n4;
``` ```
```dart title="linked_list.dart" ```dart title="linked_list.dart"
/* 連結リスト 1 -> 3 -> 2 -> 5 -> 4 を初期化 */\ /* 連結リスト 1 -> 3 -> 2 -> 5 -> 4 を初期化 */
// 各ノードを初期化 // 各ノードを初期化
ListNode n0 = ListNode(1); ListNode n0 = ListNode(1);
ListNode n1 = ListNode(3); ListNode n1 = ListNode(3);
@@ -375,9 +375,9 @@ class ListNode {
```csharp title="" ```csharp title=""
/* 双方向連結リストのノードクラス */ /* 双方向連結リストのノードクラス */
class ListNode(int x) { // コンストラクタ class ListNode(int x) { // コンストラクタ
int val = x; // ノードの値 public int val = x; // ノードの値
ListNode next; // 後続ノードへの参照 public ListNode? next; // 後続ノードへの参照
ListNode prev; // 先行ノードへの参照 public ListNode? prev; // 先行ノードへの参照
} }
``` ```

View File

@@ -79,7 +79,7 @@ List<int> nums = [1, 3, 2, 5, 4];
// 初期値なし // 初期値なし
let nums1: Vec<i32> = Vec::new(); let nums1: Vec<i32> = Vec::new();
// 初期値あり // 初期値あり
let nums: Vec<i32> = vec![1, 3, 2, 5, 4]; let mut nums: Vec<i32> = vec![1, 3, 2, 5, 4];
``` ```
```c title="list.c" ```c title="list.c"
@@ -404,10 +404,10 @@ nums.add(5);
nums.add(4); nums.add(4);
/* 途中に要素を挿入 */ /* 途中に要素を挿入 */
nums.add(3, 6); // インデックス 3 に数値 6 を挿入 nums.add(3, 6); // インデックス 3 に数値 6 を挿入
/* 要素を削除 */ /* 要素を削除 */
nums.remove(3); // インデックス 3 の要素を削除 nums.removeAt(3); // インデックス 3 の要素を削除
``` ```
```ruby title="list.rb" ```ruby title="list.rb"

View File

@@ -1,6 +1,6 @@
<!-- [snippet]{backtrack_framework} --> <!-- [snippet]{backtrack_framework} -->
```python title="" ```python title=""
def backtrack(state: State, choices: list[choice], res: list[state]): def backtrack(state: State, choices: list[Choice], res: list[State]):
"""バックトラッキングの基本形""" """バックトラッキングの基本形"""
# 解かどうかを判定 # 解かどうかを判定
if is_solution(state): if is_solution(state):
@@ -30,7 +30,7 @@ void backtrack(State *state, vector<Choice *> &choices, vector<State *> &res) {
return; return;
} }
// すべての選択肢を調べる // すべての選択肢を調べる
for (Choice choice : choices) { for (Choice *choice : choices) {
// 枝刈り:選択が有効かを判定 // 枝刈り:選択が有効かを判定
if (isValid(state, choice)) { if (isValid(state, choice)) {
// 試行:選択して状態を更新 // 試行:選択して状態を更新
@@ -189,7 +189,7 @@ function backtrack(state: State, choices: Choice[], res: State[]): void {
```dart title="" ```dart title=""
/* バックトラッキングの基本形 */ /* バックトラッキングの基本形 */
void backtrack(State state, List<Choice>, List<State> res) { void backtrack(State state, List<Choice> choices, List<State> res) {
// 解かどうかを判定 // 解かどうかを判定
if (isSolution(state)) { if (isSolution(state)) {
// 解を記録 // 解を記録

View File

@@ -196,7 +196,7 @@ function algorithm(n: number): number { // 入力データ
/* クラス */ /* クラス */
class Node { class Node {
int val; int val;
Node next; Node? next;
Node(this.val, [this.next]); Node(this.val, [this.next]);
} }
@@ -332,8 +332,9 @@ void algorithm(int n) {
void algorithm(int n) { void algorithm(int n) {
int a = 0; // O(1) int a = 0; // O(1)
int[] b = new int[10000]; // O(1) int[] b = new int[10000]; // O(1)
if (n > 10) if (n > 10) {
int[] nums = new int[n]; // O(n) int[] nums = new int[n]; // O(n)
}
} }
``` ```
@@ -353,7 +354,7 @@ func algorithm(n int) {
b := make([]int, 10000) // O(1) b := make([]int, 10000) // O(1)
var nums []int var nums []int
if n > 10 { if n > 10 {
nums := make([]int, n) // O(n) nums = make([]int, n) // O(n)
} }
fmt.Println(a, b, nums) fmt.Println(a, b, nums)
} }
@@ -413,8 +414,9 @@ fn algorithm(n: i32) {
void algorithm(int n) { void algorithm(int n) {
int a = 0; // O(1) int a = 0; // O(1)
int b[10000]; // O(1) int b[10000]; // O(1)
if (n > 10) if (n > 10) {
int nums[n] = {0}; // O(n) int nums[n]; // O(n)
}
} }
``` ```
@@ -613,7 +615,7 @@ fn function() -> i32 {
return 0; return 0;
} }
/* ループの空間計算量は O(1) */ /* ループの空間計算量は O(1) */
fn loop(n: i32) { fn for_loop(n: i32) {
for i in 0..n { for i in 0..n {
function(); function();
} }

View File

@@ -774,10 +774,10 @@ def algorithm(n)
a = 1 # +0(工夫 1) a = 1 # +0(工夫 1)
a = a + n # +0(工夫 1) a = a + n # +0(工夫 1)
# +n(工夫 2) # +n(工夫 2)
(0...(5 * n + 1)).each do { puts 0 } (0...(5 * n + 1)).each { puts 0 }
# +n*n(工夫 3) # +n*n(工夫 3)
(0...(2 * n)).each do (0...(2 * n)).each do
(0...(n + 1)).each do { puts 0 } (0...(n + 1)).each { puts 0 }
end end
end end
``` ```

View File

@@ -96,7 +96,7 @@ val bools = BooleanArray(5)
```ruby title="" ```ruby title=""
# Ruby のリストには、さまざまな基本データ型やオブジェクトへの参照を自由に格納できる # Ruby のリストには、さまざまな基本データ型やオブジェクトへの参照を自由に格納できる
data = [0, 0.0, 'a', false, ListNode(0)] data = [0, 0.0, 'a', false, ListNode.new(0)]
``` ```
<!-- [tutor]{basic_type_arrays_tutor} --> <!-- [tutor]{basic_type_arrays_tutor} -->

View File

@@ -184,7 +184,7 @@ map[10583] = "小鸭";
/* 照会操作 */ /* 照会操作 */
// キー key を入力して値 value を取得 // キー key を入力して値 value を取得
String name = map[15937]; String? name = map[15937];
/* 削除操作 */ /* 削除操作 */
// ハッシュテーブルからペア (key, value) を削除 // ハッシュテーブルからペア (key, value) を削除
@@ -202,7 +202,7 @@ let mut map: HashMap<i32, String> = HashMap::new();
map.insert(12836, "小哈".to_string()); map.insert(12836, "小哈".to_string());
map.insert(15937, "小啰".to_string()); map.insert(15937, "小啰".to_string());
map.insert(16750, "小算".to_string()); map.insert(16750, "小算".to_string());
map.insert(13279, "小法".to_string()); map.insert(13276, "小法".to_string());
map.insert(10583, "小鸭".to_string()); map.insert(10583, "小鸭".to_string());
/* 照会操作 */ /* 照会操作 */

View File

@@ -71,7 +71,7 @@ bool isEmpty = maxHeap.empty();
/* リストを入力してヒープを構築 */ /* リストを入力してヒープを構築 */
vector<int> input{1, 3, 2, 5, 4}; vector<int> input{1, 3, 2, 5, 4};
priority_queue<int, vector<int>, greater<int>> minHeap(input.begin(), input.end()); minHeap = priority_queue<int, vector<int>, greater<int>>(input.begin(), input.end());
``` ```
```java title="heap.java" ```java title="heap.java"

View File

@@ -28,8 +28,8 @@ class ListNode {
```csharp title="" ```csharp title=""
/* 연결 리스트 노드 클래스 */ /* 연결 리스트 노드 클래스 */
class ListNode(int x) { //생성자 class ListNode(int x) { //생성자
int val = x; // 노드 값 public int val = x; // 노드 값
ListNode? next; // 다음 노드를 가리키는 참조 public ListNode? next; // 다음 노드를 가리키는 참조
} }
``` ```
@@ -264,7 +264,7 @@ n3.next = n4;
``` ```
```dart title="linked_list.dart" ```dart title="linked_list.dart"
/* 연결 리스트 1 -> 3 -> 2 -> 5 -> 4 초기화 */\ /* 연결 리스트 1 -> 3 -> 2 -> 5 -> 4 초기화 */
// 각 노드 초기화 // 각 노드 초기화
ListNode n0 = ListNode(1); ListNode n0 = ListNode(1);
ListNode n1 = ListNode(3); ListNode n1 = ListNode(3);
@@ -375,9 +375,9 @@ class ListNode {
```csharp title="" ```csharp title=""
/* 이중 연결 리스트 노드 클래스 */ /* 이중 연결 리스트 노드 클래스 */
class ListNode(int x) { // 생성자 class ListNode(int x) { // 생성자
int val = x; // 노드 값 public int val = x; // 노드 값
ListNode next; // 후속 노드를 가리키는 참조 public ListNode? next; // 후속 노드를 가리키는 참조
ListNode prev; // 선행 노드를 가리키는 참조 public ListNode? prev; // 선행 노드를 가리키는 참조
} }
``` ```

View File

@@ -79,7 +79,7 @@ List<int> nums = [1, 3, 2, 5, 4];
// 초깃값 없음 // 초깃값 없음
let nums1: Vec<i32> = Vec::new(); let nums1: Vec<i32> = Vec::new();
// 초깃값 지정 // 초깃값 지정
let nums: Vec<i32> = vec![1, 3, 2, 5, 4]; let mut nums: Vec<i32> = vec![1, 3, 2, 5, 4];
``` ```
```c title="list.c" ```c title="list.c"
@@ -404,10 +404,10 @@ nums.add(5);
nums.add(4); nums.add(4);
/* 중간에 원소 삽입 */ /* 중간에 원소 삽입 */
nums.add(3, 6); // 인덱스 3에 숫자 6 삽입 nums.add(3, 6); // 인덱스 3에 숫자 6 삽입
/* 원소 삭제 */ /* 원소 삭제 */
nums.remove(3); // 인덱스 3의 원소 삭제 nums.removeAt(3); // 인덱스 3의 원소 삭제
``` ```
```ruby title="list.rb" ```ruby title="list.rb"

View File

@@ -1,6 +1,6 @@
<!-- [snippet]{backtrack_framework} --> <!-- [snippet]{backtrack_framework} -->
```python title="" ```python title=""
def backtrack(state: State, choices: list[choice], res: list[state]): def backtrack(state: State, choices: list[Choice], res: list[State]):
"""백트래킹 알고리즘의 기본 틀""" """백트래킹 알고리즘의 기본 틀"""
# 해인지 확인 # 해인지 확인
if is_solution(state): if is_solution(state):
@@ -30,7 +30,7 @@ void backtrack(State *state, vector<Choice *> &choices, vector<State *> &res) {
return; return;
} }
// 모든 선택지 순회 // 모든 선택지 순회
for (Choice choice : choices) { for (Choice *choice : choices) {
// 가지치기: 선택이 유효한지 확인 // 가지치기: 선택이 유효한지 확인
if (isValid(state, choice)) { if (isValid(state, choice)) {
// 시도: 선택하고 상태 갱신 // 시도: 선택하고 상태 갱신
@@ -189,7 +189,7 @@ function backtrack(state: State, choices: Choice[], res: State[]): void {
```dart title="" ```dart title=""
/* 백트래킹 알고리즘의 기본 틀 */ /* 백트래킹 알고리즘의 기본 틀 */
void backtrack(State state, List<Choice>, List<State> res) { void backtrack(State state, List<Choice> choices, List<State> res) {
// 해인지 확인 // 해인지 확인
if (isSolution(state)) { if (isSolution(state)) {
// 해 기록 // 해 기록

View File

@@ -196,7 +196,7 @@ function algorithm(n: number): number { // 입력 데이터
/* 클래스 */ /* 클래스 */
class Node { class Node {
int val; int val;
Node next; Node? next;
Node(this.val, [this.next]); Node(this.val, [this.next]);
} }
@@ -332,8 +332,9 @@ void algorithm(int n) {
void algorithm(int n) { void algorithm(int n) {
int a = 0; // O(1) int a = 0; // O(1)
int[] b = new int[10000]; // O(1) int[] b = new int[10000]; // O(1)
if (n > 10) if (n > 10) {
int[] nums = new int[n]; // O(n) int[] nums = new int[n]; // O(n)
}
} }
``` ```
@@ -353,7 +354,7 @@ func algorithm(n int) {
b := make([]int, 10000) // O(1) b := make([]int, 10000) // O(1)
var nums []int var nums []int
if n > 10 { if n > 10 {
nums := make([]int, n) // O(n) nums = make([]int, n) // O(n)
} }
fmt.Println(a, b, nums) fmt.Println(a, b, nums)
} }
@@ -413,8 +414,9 @@ fn algorithm(n: i32) {
void algorithm(int n) { void algorithm(int n) {
int a = 0; // O(1) int a = 0; // O(1)
int b[10000]; // O(1) int b[10000]; // O(1)
if (n > 10) if (n > 10) {
int nums[n] = {0}; // O(n) int nums[n]; // O(n)
}
} }
``` ```
@@ -613,7 +615,7 @@ fn function() -> i32 {
return 0; return 0;
} }
/* 반복문의 공간 복잡도는 O(1) */ /* 반복문의 공간 복잡도는 O(1) */
fn loop(n: i32) { fn for_loop(n: i32) {
for i in 0..n { for i in 0..n {
function(); function();
} }

View File

@@ -774,10 +774,10 @@ def algorithm(n)
a = 1 # +0(요령 1) a = 1 # +0(요령 1)
a = a + n # +0(요령 1) a = a + n # +0(요령 1)
# +n(요령 2) # +n(요령 2)
(0...(5 * n + 1)).each do { puts 0 } (0...(5 * n + 1)).each { puts 0 }
# +n*n(요령 3) # +n*n(요령 3)
(0...(2 * n)).each do (0...(2 * n)).each do
(0...(n + 1)).each do { puts 0 } (0...(n + 1)).each { puts 0 }
end end
end end
``` ```

View File

@@ -96,7 +96,7 @@ val bools = BooleanArray(5)
```ruby title="" ```ruby title=""
# Ruby의 리스트는 여러 기본 자료형과 객체 참조를 자유롭게 저장할 수 있다 # Ruby의 리스트는 여러 기본 자료형과 객체 참조를 자유롭게 저장할 수 있다
data = [0, 0.0, 'a', false, ListNode(0)] data = [0, 0.0, 'a', false, ListNode.new(0)]
``` ```
<!-- [tutor]{basic_type_arrays_tutor} --> <!-- [tutor]{basic_type_arrays_tutor} -->

View File

@@ -184,7 +184,7 @@ map[10583] = "小鸭";
/* 조회 연산 */ /* 조회 연산 */
// 해시 테이블에 키 key를 입력하여 값 value를 얻음 // 해시 테이블에 키 key를 입력하여 값 value를 얻음
String name = map[15937]; String? name = map[15937];
/* 삭제 연산 */ /* 삭제 연산 */
// 해시 테이블에서 키-값 쌍 (key, value) 삭제 // 해시 테이블에서 키-값 쌍 (key, value) 삭제
@@ -202,7 +202,7 @@ let mut map: HashMap<i32, String> = HashMap::new();
map.insert(12836, "小哈".to_string()); map.insert(12836, "小哈".to_string());
map.insert(15937, "小啰".to_string()); map.insert(15937, "小啰".to_string());
map.insert(16750, "小算".to_string()); map.insert(16750, "小算".to_string());
map.insert(13279, "小法".to_string()); map.insert(13276, "小法".to_string());
map.insert(10583, "小鸭".to_string()); map.insert(10583, "小鸭".to_string());
/* 조회 연산 */ /* 조회 연산 */

View File

@@ -71,7 +71,7 @@ bool isEmpty = maxHeap.empty();
/* 리스트를 입력받아 힙 구성 */ /* 리스트를 입력받아 힙 구성 */
vector<int> input{1, 3, 2, 5, 4}; vector<int> input{1, 3, 2, 5, 4};
priority_queue<int, vector<int>, greater<int>> minHeap(input.begin(), input.end()); minHeap = priority_queue<int, vector<int>, greater<int>>(input.begin(), input.end());
``` ```
```java title="heap.java" ```java title="heap.java"

View File

@@ -28,8 +28,8 @@ class ListNode {
```csharp title="" ```csharp title=""
/* Класс узла связного списка */ /* Класс узла связного списка */
class ListNode(int x) { // Конструктор class ListNode(int x) { // Конструктор
int val = x; // Значение узла public int val = x; // Значение узла
ListNode? next; // Ссылка на следующий узел public ListNode? next; // Ссылка на следующий узел
} }
``` ```
@@ -264,7 +264,7 @@ n3.next = n4;
``` ```
```dart title="linked_list.dart" ```dart title="linked_list.dart"
/* Инициализация связного списка 1 -> 3 -> 2 -> 5 -> 4 */\ /* Инициализация связного списка 1 -> 3 -> 2 -> 5 -> 4 */
// Инициализация каждого узла // Инициализация каждого узла
ListNode n0 = ListNode(1); ListNode n0 = ListNode(1);
ListNode n1 = ListNode(3); ListNode n1 = ListNode(3);
@@ -375,9 +375,9 @@ class ListNode {
```csharp title="" ```csharp title=""
/* Класс узла двусвязного списка */ /* Класс узла двусвязного списка */
class ListNode(int x) { // Конструктор class ListNode(int x) { // Конструктор
int val = x; // Значение узла public int val = x; // Значение узла
ListNode next; // Ссылка на следующий узел public ListNode? next; // Ссылка на следующий узел
ListNode prev; // Ссылка на предыдущий узел public ListNode? prev; // Ссылка на предыдущий узел
} }
``` ```

View File

@@ -79,7 +79,7 @@ List<int> nums = [1, 3, 2, 5, 4];
// Без начальных значений // Без начальных значений
let nums1: Vec<i32> = Vec::new(); let nums1: Vec<i32> = Vec::new();
// С начальными значениями // С начальными значениями
let nums: Vec<i32> = vec![1, 3, 2, 5, 4]; let mut nums: Vec<i32> = vec![1, 3, 2, 5, 4];
``` ```
```c title="list.c" ```c title="list.c"
@@ -404,10 +404,10 @@ nums.add(5);
nums.add(4); nums.add(4);
/* Вставить элемент в середину */ /* Вставить элемент в середину */
nums.add(3, 6); // Вставить число 6 по индексу 3 nums.add(3, 6); // Вставить число 6 по индексу 3
/* Удалить элемент */ /* Удалить элемент */
nums.remove(3); // Удалить элемент по индексу 3 nums.removeAt(3); // Удалить элемент по индексу 3
``` ```
```ruby title="list.rb" ```ruby title="list.rb"

View File

@@ -1,6 +1,6 @@
<!-- [snippet]{backtrack_framework} --> <!-- [snippet]{backtrack_framework} -->
```python title="" ```python title=""
def backtrack(state: State, choices: list[choice], res: list[state]): def backtrack(state: State, choices: list[Choice], res: list[State]):
"""Каркас алгоритма поиска с возвратом""" """Каркас алгоритма поиска с возвратом"""
# Проверка, является ли текущее состояние решением # Проверка, является ли текущее состояние решением
if is_solution(state): if is_solution(state):
@@ -30,7 +30,7 @@ void backtrack(State *state, vector<Choice *> &choices, vector<State *> &res) {
return; return;
} }
// Перебор всех возможных выборов // Перебор всех возможных выборов
for (Choice choice : choices) { for (Choice *choice : choices) {
// Обрезка: проверка допустимости выбора // Обрезка: проверка допустимости выбора
if (isValid(state, choice)) { if (isValid(state, choice)) {
// Попытка: сделать выбор и обновить состояние // Попытка: сделать выбор и обновить состояние
@@ -189,7 +189,7 @@ function backtrack(state: State, choices: Choice[], res: State[]): void {
```dart title="" ```dart title=""
/* Каркас алгоритма поиска с возвратом */ /* Каркас алгоритма поиска с возвратом */
void backtrack(State state, List<Choice>, List<State> res) { void backtrack(State state, List<Choice> choices, List<State> res) {
// Проверка, является ли текущее состояние решением // Проверка, является ли текущее состояние решением
if (isSolution(state)) { if (isSolution(state)) {
// Запись решения // Запись решения

View File

@@ -196,7 +196,7 @@ function algorithm(n: number): number { // Входные данные
/* Класс */ /* Класс */
class Node { class Node {
int val; int val;
Node next; Node? next;
Node(this.val, [this.next]); Node(this.val, [this.next]);
} }
@@ -332,8 +332,9 @@ void algorithm(int n) {
void algorithm(int n) { void algorithm(int n) {
int a = 0; // O(1) int a = 0; // O(1)
int[] b = new int[10000]; // O(1) int[] b = new int[10000]; // O(1)
if (n > 10) if (n > 10) {
int[] nums = new int[n]; // O(n) int[] nums = new int[n]; // O(n)
}
} }
``` ```
@@ -353,7 +354,7 @@ func algorithm(n int) {
b := make([]int, 10000) // O(1) b := make([]int, 10000) // O(1)
var nums []int var nums []int
if n > 10 { if n > 10 {
nums := make([]int, n) // O(n) nums = make([]int, n) // O(n)
} }
fmt.Println(a, b, nums) fmt.Println(a, b, nums)
} }
@@ -413,8 +414,9 @@ fn algorithm(n: i32) {
void algorithm(int n) { void algorithm(int n) {
int a = 0; // O(1) int a = 0; // O(1)
int b[10000]; // O(1) int b[10000]; // O(1)
if (n > 10) if (n > 10) {
int nums[n] = {0}; // O(n) int nums[n]; // O(n)
}
} }
``` ```
@@ -613,7 +615,7 @@ fn function() -> i32 {
return 0; return 0;
} }
/* Пространственная сложность цикла равна O(1) */ /* Пространственная сложность цикла равна O(1) */
fn loop(n: i32) { fn for_loop(n: i32) {
for i in 0..n { for i in 0..n {
function(); function();
} }

View File

@@ -774,10 +774,10 @@ def algorithm(n)
a = 1 # +0 (прием 1) a = 1 # +0 (прием 1)
a = a + n # +0 (прием 1) a = a + n # +0 (прием 1)
# +n (прием 2) # +n (прием 2)
(0...(5 * n + 1)).each do { puts 0 } (0...(5 * n + 1)).each { puts 0 }
# +n*n (прием 3) # +n*n (прием 3)
(0...(2 * n)).each do (0...(2 * n)).each do
(0...(n + 1)).each do { puts 0 } (0...(n + 1)).each { puts 0 }
end end
end end
``` ```

View File

@@ -96,7 +96,7 @@ val bools = BooleanArray(5)
```ruby title="" ```ruby title=""
# Списки Ruby могут свободно хранить различные базовые типы данных и ссылки на объекты # Списки Ruby могут свободно хранить различные базовые типы данных и ссылки на объекты
data = [0, 0.0, 'a', false, ListNode(0)] data = [0, 0.0, 'a', false, ListNode.new(0)]
``` ```
<!-- [tutor]{basic_type_arrays_tutor} --> <!-- [tutor]{basic_type_arrays_tutor} -->

View File

@@ -184,7 +184,7 @@ map[10583] = "Сяо Я";
/* Операция поиска */ /* Операция поиска */
// Передать в хеш-таблицу ключ key и получить значение value // Передать в хеш-таблицу ключ key и получить значение value
String name = map[15937]; String? name = map[15937];
/* Операция удаления */ /* Операция удаления */
// Удалить пару ключ-значение (key, value) из хеш-таблицы // Удалить пару ключ-значение (key, value) из хеш-таблицы
@@ -202,7 +202,7 @@ let mut map: HashMap<i32, String> = HashMap::new();
map.insert(12836, "Сяо Ха".to_string()); map.insert(12836, "Сяо Ха".to_string());
map.insert(15937, "Сяо Ло".to_string()); map.insert(15937, "Сяо Ло".to_string());
map.insert(16750, "Сяо Суань".to_string()); map.insert(16750, "Сяо Суань".to_string());
map.insert(13279, "Сяо Фа".to_string()); map.insert(13276, "Сяо Фа".to_string());
map.insert(10583, "Сяо Я".to_string()); map.insert(10583, "Сяо Я".to_string());
/* Операция поиска */ /* Операция поиска */

View File

@@ -71,7 +71,7 @@ bool isEmpty = maxHeap.empty();
/* Построение кучи из входного списка */ /* Построение кучи из входного списка */
vector<int> input{1, 3, 2, 5, 4}; vector<int> input{1, 3, 2, 5, 4};
priority_queue<int, vector<int>, greater<int>> minHeap(input.begin(), input.end()); minHeap = priority_queue<int, vector<int>, greater<int>>(input.begin(), input.end());
``` ```
```java title="heap.java" ```java title="heap.java"

View File

@@ -28,8 +28,8 @@ class ListNode {
```csharp title="" ```csharp title=""
/* 鏈結串列節點類別 */ /* 鏈結串列節點類別 */
class ListNode(int x) { //建構子 class ListNode(int x) { //建構子
int val = x; // 節點值 public int val = x; // 節點值
ListNode? next; // 指向下一節點的引用 public ListNode? next; // 指向下一節點的引用
} }
``` ```
@@ -264,7 +264,7 @@ n3.next = n4;
``` ```
```dart title="linked_list.dart" ```dart title="linked_list.dart"
/* 初始化鏈結串列 1 -> 3 -> 2 -> 5 -> 4 */\ /* 初始化鏈結串列 1 -> 3 -> 2 -> 5 -> 4 */
// 初始化各個節點 // 初始化各個節點
ListNode n0 = ListNode(1); ListNode n0 = ListNode(1);
ListNode n1 = ListNode(3); ListNode n1 = ListNode(3);
@@ -375,9 +375,9 @@ class ListNode {
```csharp title="" ```csharp title=""
/* 雙向鏈結串列節點類別 */ /* 雙向鏈結串列節點類別 */
class ListNode(int x) { // 建構子 class ListNode(int x) { // 建構子
int val = x; // 節點值 public int val = x; // 節點值
ListNode next; // 指向後繼節點的引用 public ListNode? next; // 指向後繼節點的引用
ListNode prev; // 指向前驅節點的引用 public ListNode? prev; // 指向前驅節點的引用
} }
``` ```

View File

@@ -79,7 +79,7 @@ List<int> nums = [1, 3, 2, 5, 4];
// 無初始值 // 無初始值
let nums1: Vec<i32> = Vec::new(); let nums1: Vec<i32> = Vec::new();
// 有初始值 // 有初始值
let nums: Vec<i32> = vec![1, 3, 2, 5, 4]; let mut nums: Vec<i32> = vec![1, 3, 2, 5, 4];
``` ```
```c title="list.c" ```c title="list.c"
@@ -404,10 +404,10 @@ nums.add(5);
nums.add(4); nums.add(4);
/* 在中間插入元素 */ /* 在中間插入元素 */
nums.add(3, 6); // 在索引 3 處插入數字 6 nums.add(3, 6); // 在索引 3 處插入數字 6
/* 刪除元素 */ /* 刪除元素 */
nums.remove(3); // 刪除索引 3 處的元素 nums.removeAt(3); // 刪除索引 3 處的元素
``` ```
```ruby title="list.rb" ```ruby title="list.rb"

View File

@@ -1,6 +1,6 @@
<!-- [snippet]{backtrack_framework} --> <!-- [snippet]{backtrack_framework} -->
```python title="" ```python title=""
def backtrack(state: State, choices: list[choice], res: list[state]): def backtrack(state: State, choices: list[Choice], res: list[State]):
"""回溯演算法框架""" """回溯演算法框架"""
# 判斷是否為解 # 判斷是否為解
if is_solution(state): if is_solution(state):
@@ -30,7 +30,7 @@ void backtrack(State *state, vector<Choice *> &choices, vector<State *> &res) {
return; return;
} }
// 走訪所有選擇 // 走訪所有選擇
for (Choice choice : choices) { for (Choice *choice : choices) {
// 剪枝:判斷選擇是否合法 // 剪枝:判斷選擇是否合法
if (isValid(state, choice)) { if (isValid(state, choice)) {
// 嘗試:做出選擇,更新狀態 // 嘗試:做出選擇,更新狀態
@@ -189,7 +189,7 @@ function backtrack(state: State, choices: Choice[], res: State[]): void {
```dart title="" ```dart title=""
/* 回溯演算法框架 */ /* 回溯演算法框架 */
void backtrack(State state, List<Choice>, List<State> res) { void backtrack(State state, List<Choice> choices, List<State> res) {
// 判斷是否為解 // 判斷是否為解
if (isSolution(state)) { if (isSolution(state)) {
// 記錄解 // 記錄解

View File

@@ -196,7 +196,7 @@ function algorithm(n: number): number { // 輸入資料
/* 類別 */ /* 類別 */
class Node { class Node {
int val; int val;
Node next; Node? next;
Node(this.val, [this.next]); Node(this.val, [this.next]);
} }
@@ -332,8 +332,9 @@ void algorithm(int n) {
void algorithm(int n) { void algorithm(int n) {
int a = 0; // O(1) int a = 0; // O(1)
int[] b = new int[10000]; // O(1) int[] b = new int[10000]; // O(1)
if (n > 10) if (n > 10) {
int[] nums = new int[n]; // O(n) int[] nums = new int[n]; // O(n)
}
} }
``` ```
@@ -353,7 +354,7 @@ func algorithm(n int) {
b := make([]int, 10000) // O(1) b := make([]int, 10000) // O(1)
var nums []int var nums []int
if n > 10 { if n > 10 {
nums := make([]int, n) // O(n) nums = make([]int, n) // O(n)
} }
fmt.Println(a, b, nums) fmt.Println(a, b, nums)
} }
@@ -413,8 +414,9 @@ fn algorithm(n: i32) {
void algorithm(int n) { void algorithm(int n) {
int a = 0; // O(1) int a = 0; // O(1)
int b[10000]; // O(1) int b[10000]; // O(1)
if (n > 10) if (n > 10) {
int nums[n] = {0}; // O(n) int nums[n]; // O(n)
}
} }
``` ```
@@ -613,7 +615,7 @@ fn function() -> i32 {
return 0; return 0;
} }
/* 迴圈的空間複雜度為 O(1) */ /* 迴圈的空間複雜度為 O(1) */
fn loop(n: i32) { fn for_loop(n: i32) {
for i in 0..n { for i in 0..n {
function(); function();
} }

View File

@@ -774,10 +774,10 @@ def algorithm(n)
a = 1 # +0(技巧 1) a = 1 # +0(技巧 1)
a = a + n # +0(技巧 1) a = a + n # +0(技巧 1)
# +n(技巧 2) # +n(技巧 2)
(0...(5 * n + 1)).each do { puts 0 } (0...(5 * n + 1)).each { puts 0 }
# +n*n(技巧 3) # +n*n(技巧 3)
(0...(2 * n)).each do (0...(2 * n)).each do
(0...(n + 1)).each do { puts 0 } (0...(n + 1)).each { puts 0 }
end end
end end
``` ```

View File

@@ -96,7 +96,7 @@ val bools = BooleanArray(5)
```ruby title="" ```ruby title=""
# Ruby 的串列可以自由儲存各種基本資料型別和物件引用 # Ruby 的串列可以自由儲存各種基本資料型別和物件引用
data = [0, 0.0, 'a', false, ListNode(0)] data = [0, 0.0, 'a', false, ListNode.new(0)]
``` ```
<!-- [tutor]{basic_type_arrays_tutor} --> <!-- [tutor]{basic_type_arrays_tutor} -->

View File

@@ -184,7 +184,7 @@ map[10583] = "小鴨";
/* 查詢操作 */ /* 查詢操作 */
// 向雜湊表中輸入鍵 key ,得到值 value // 向雜湊表中輸入鍵 key ,得到值 value
String name = map[15937]; String? name = map[15937];
/* 刪除操作 */ /* 刪除操作 */
// 在雜湊表中刪除鍵值對 (key, value) // 在雜湊表中刪除鍵值對 (key, value)
@@ -202,7 +202,7 @@ let mut map: HashMap<i32, String> = HashMap::new();
map.insert(12836, "小哈".to_string()); map.insert(12836, "小哈".to_string());
map.insert(15937, "小囉".to_string()); map.insert(15937, "小囉".to_string());
map.insert(16750, "小算".to_string()); map.insert(16750, "小算".to_string());
map.insert(13279, "小法".to_string()); map.insert(13276, "小法".to_string());
map.insert(10583, "小鴨".to_string()); map.insert(10583, "小鴨".to_string());
/* 查詢操作 */ /* 查詢操作 */

View File

@@ -71,7 +71,7 @@ bool isEmpty = maxHeap.empty();
/* 輸入串列並建堆積 */ /* 輸入串列並建堆積 */
vector<int> input{1, 3, 2, 5, 4}; vector<int> input{1, 3, 2, 5, 4};
priority_queue<int, vector<int>, greater<int>> minHeap(input.begin(), input.end()); minHeap = priority_queue<int, vector<int>, greater<int>>(input.begin(), input.end());
``` ```
```java title="heap.java" ```java title="heap.java"