Hello 算法 1.2.0 繁体中文 TypeScript 版
/* 類別 */ class Node { val: number; next: Node | null; constructor(val?: number) { this.val = val === undefined ? 0 : val; // 節點值 this.next = null; // 指向下一節點的引用 } } /* 函式 */ function constFunc(): quadratic(n: number): void { // 矩陣佔用 O(n^2) 空間 const numMatrix = Array(n) .fill(null) .map(() => Array(n).fill(null)); // 二維串列佔用 O(n^2) 空間 const numList = []; for (let i = 0; i < n; i++) { const space_complexity.ts === /* 指數階(建立滿二元樹) */ function buildTree(n: number): TreeNode | null { if (n === 0) return null; 第 2 章 複雜度分析 www.hello‑algo.com 48 const root = new TreeNode(0); root.left = buildTree(n0 码力 | 384 页 | 18.80 MB | 9 月前3Hello 算法 1.2.0 繁体中文 C语言 版
(int i = 0; i < n; i++) { free(nodes[i]); } free(nodes); // 長度為 n 的雜湊表佔用 O(n) 空間 HashTable *h = NULL; for (int i = 0; i < n; i++) { HashTable *tmp = malloc(sizeof(HashTable)); tmp->key = i; tmp->val File: space_complexity.c === /* 指數階(建立滿二元樹) */ TreeNode *buildTree(int n) { if (n == 0) return NULL; TreeNode *root = newTreeNode(0); root->left = buildTree(n - 1); root->right = buildTree(n - 1); “值”和指向下 一節點的“引用”。 ‧ 鏈結串列的首個節點被稱為“頭節點”,最後一個節點被稱為“尾節點”。 ‧ 尾節點指向的是“空”,它在 Java、C++ 和 Python 中分別被記為 null、nullptr 和 None 。 ‧ 在 C、C++、Go 和 Rust 等支持指標的語言中,上述“引用”應被替換為“指標”。 如以下程式碼所示,鏈結串列節點 ListNode 除了包含值,0 码力 | 392 页 | 18.83 MB | 9 月前3Hello 算法 1.2.0 繁体中文 JavaScript 版
Node { val; next; constructor(val) { this.val = val === undefined ? 0 : val; // 節點值 this.next = null; // 指向下一節點的引用 } } /* 函式 */ function constFunc() { // 執行某些操作 第 2 章 複雜度分析 www.hello‑algo.com 43 */ function quadratic(n) { // 矩陣佔用 O(n^2) 空間 const numMatrix = Array(n) .fill(null) .map(() => Array(n).fill(null)); // 二維串列佔用 O(n^2) 空間 const numList = []; for (let i = 0; i < n; i++) { const === File: space_complexity.js === /* 指數階(建立滿二元樹) */ function buildTree(n) { if (n === 0) return null; 第 2 章 複雜度分析 www.hello‑algo.com 48 const root = new TreeNode(0); root.left = buildTree(n - 1);0 码力 | 379 页 | 18.78 MB | 9 月前3Hello 算法 1.2.0 繁体中文 Kotlin 版
圖 2‑15 所示。 圖 2‑15 演算法使用的相關空間 相關程式碼如下: /* 類別 */ class Node(var _val: Int) { var next: Node? = null } /* 函式 */ fun function(): Int { // 執行某些操作... return 0 } fun algorithm(n: Int): Int { // 輸入資料 space_complexity.kt === /* 指數階(建立滿二元樹) */ fun buildTree(n: Int): TreeNode? { if (n == 0) return null val root = TreeNode(0) root.left = buildTree(n - 1) root.right = buildTree(n - 1) return root “值”和指向下 一節點的“引用”。 ‧ 鏈結串列的首個節點被稱為“頭節點”,最後一個節點被稱為“尾節點”。 ‧ 尾節點指向的是“空”,它在 Java、C++ 和 Python 中分別被記為 null、nullptr 和 None 。 ‧ 在 C、C++、Go 和 Rust 等支持指標的語言中,上述“引用”應被替換為“指標”。 如以下程式碼所示,鏈結串列節點 ListNode 除了包含值,0 码力 | 382 页 | 18.79 MB | 9 月前3Hello 算法 1.2.0 繁体中文 Dart 版
File: space_complexity.dart === /* 指數階(建立滿二元樹) */ TreeNode? buildTree(int n) { if (n == 0) return null; TreeNode root = TreeNode(0); root.left = buildTree(n - 1); root.right = buildTree(n - 1); return “值”和指向下 一節點的“引用”。 ‧ 鏈結串列的首個節點被稱為“頭節點”,最後一個節點被稱為“尾節點”。 ‧ 尾節點指向的是“空”,它在 Java、C++ 和 Python 中分別被記為 null、nullptr 和 None 。 ‧ 在 C、C++、Go 和 Rust 等支持指標的語言中,上述“引用”應被替換為“指標”。 如以下程式碼所示,鏈結串列節點 ListNode 除了包含值, File: linked_list.dart === /* 刪除鏈結串列的節點 n0 之後的首個節點 */ void remove(ListNode n0) { if (n0.next == null) return; // n0 -> P -> n1 ListNode P = n0.next!; ListNode? n1 = P.next; n0.next = n1; } 第 40 码力 | 378 页 | 18.77 MB | 9 月前3Hello 算法 1.2.0 繁体中文 C# 版
File: space_complexity.cs === /* 指數階(建立滿二元樹) */ TreeNode? BuildTree(int n) { if (n == 0) return null; TreeNode root = new(0) { left = BuildTree(n - 1), right = BuildTree(n - 1) }; return root; “值”和指向下 一節點的“引用”。 ‧ 鏈結串列的首個節點被稱為“頭節點”,最後一個節點被稱為“尾節點”。 ‧ 尾節點指向的是“空”,它在 Java、C++ 和 Python 中分別被記為 null、nullptr 和 None 。 ‧ 在 C、C++、Go 和 Rust 等支持指標的語言中,上述“引用”應被替換為“指標”。 如以下程式碼所示,鏈結串列節點 ListNode 除了包含值, === File: linked_list.cs === /* 刪除鏈結串列的節點 n0 之後的首個節點 */ void Remove(ListNode n0) { if (n0.next == null) return; // n0 -> P -> n1 ListNode P = n0.next; ListNode? n1 = P.next; n0.next = n1; } 4. 訪問節點0 码力 | 379 页 | 18.79 MB | 9 月前3Hello 算法 1.2.0 繁体中文 Java 版
File: space_complexity.java === /* 指數階(建立滿二元樹) */ TreeNode buildTree(int n) { if (n == 0) return null; TreeNode root = new TreeNode(0); root.left = buildTree(n - 1); root.right = buildTree(n - 1); “值”和指向下 一節點的“引用”。 ‧ 鏈結串列的首個節點被稱為“頭節點”,最後一個節點被稱為“尾節點”。 ‧ 尾節點指向的是“空”,它在 Java、C++ 和 Python 中分別被記為 null、nullptr 和 None 。 ‧ 在 C、C++、Go 和 Rust 等支持指標的語言中,上述“引用”應被替換為“指標”。 如以下程式碼所示,鏈結串列節點 ListNode 除了包含值, File: linked_list.java === /* 刪除鏈結串列的節點 n0 之後的首個節點 */ void remove(ListNode n0) { if (n0.next == null) return; // n0 -> P -> n1 ListNode P = n0.next; ListNode n1 = P.next; n0.next = n1; } 4. 訪問節點0 码力 | 379 页 | 18.79 MB | 9 月前3Julia 1.11.4
ERROR: UndefRefError: access to undefined reference This avoids the need to continually check for null values. However, not all object fields are references. Julia considers some types to be "plain data" raw pointer value must be called at runtime for precompilation to work (Ptr objects will turn into null pointers unless they are hidden inside an isbits object). This includes the return values of the the missing object, which is the singleton instance of the type Missing. missing is equivalent to NULL in SQL and NA in R, and behaves like them in most situations. 21.1 Propagation of Missing Values0 码力 | 2007 页 | 6.73 MB | 3 月前3Julia 1.11.5 Documentation
ERROR: UndefRefError: access to undefined reference This avoids the need to continually check for null values. However, not all object fields are references. Julia considers some types to be "plain data" raw pointer value must be called at runtime for precompilation to work (Ptr objects will turn into null pointers unless they are hidden inside an isbits object). This includes the return values of the the missing object, which is the singleton instance of the type Missing. missing is equivalent to NULL in SQL and NA in R, and behaves like them in most situations. 21.1 Propagation of Missing Values0 码力 | 2007 页 | 6.73 MB | 3 月前3Julia 1.11.6 Release Notes
ERROR: UndefRefError: access to undefined reference This avoids the need to continually check for null values. However, not all object fields are references. Julia considers some types to be "plain data" raw pointer value must be called at runtime for precompilation to work (Ptr objects will turn into null pointers unless they are hidden inside an isbits object). This includes the return values of the the missing object, which is the singleton instance of the type Missing. missing is equivalent to NULL in SQL and NA in R, and behaves like them in most situations. 21.1 Propagation of Missing Values0 码力 | 2007 页 | 6.73 MB | 3 月前3
共 36 条
- 1
- 2
- 3
- 4