feat: Traditional Chinese version (#1163)

* First commit

* Update mkdocs.yml

* Translate all the docs to traditional Chinese

* Translate the code files.

* Translate the docker file

* Fix mkdocs.yml

* Translate all the figures from SC to TC

* 二叉搜尋樹 -> 二元搜尋樹

* Update terminology.

* Update terminology

* 构造函数/构造方法 -> 建構子
异或 -> 互斥或

* 擴充套件 -> 擴展

* constant - 常量 - 常數

* 類	-> 類別

* AVL -> AVL 樹

* 數組 -> 陣列

* 係統 -> 系統
斐波那契數列 -> 費波那契數列
運算元量 -> 運算量
引數 -> 參數

* 聯絡 -> 關聯

* 麵試 -> 面試

* 面向物件 -> 物件導向
歸併排序 -> 合併排序
范式 -> 範式

* Fix 算法 -> 演算法

* 錶示 -> 表示
反碼 -> 一補數
補碼 -> 二補數
列列尾部 -> 佇列尾部
區域性性 -> 區域性
一摞 -> 一疊

* Synchronize with main branch

* 賬號 -> 帳號
推匯 -> 推導

* Sync with main branch

* First commit

* Update mkdocs.yml

* Translate all the docs to traditional Chinese

* Translate the code files.

* Translate the docker file

* Fix mkdocs.yml

* Translate all the figures from SC to TC

* 二叉搜尋樹 -> 二元搜尋樹

* Update terminology

* 构造函数/构造方法 -> 建構子
异或 -> 互斥或

* 擴充套件 -> 擴展

* constant - 常量 - 常數

* 類	-> 類別

* AVL -> AVL 樹

* 數組 -> 陣列

* 係統 -> 系統
斐波那契數列 -> 費波那契數列
運算元量 -> 運算量
引數 -> 參數

* 聯絡 -> 關聯

* 麵試 -> 面試

* 面向物件 -> 物件導向
歸併排序 -> 合併排序
范式 -> 範式

* Fix 算法 -> 演算法

* 錶示 -> 表示
反碼 -> 一補數
補碼 -> 二補數
列列尾部 -> 佇列尾部
區域性性 -> 區域性
一摞 -> 一疊

* Synchronize with main branch

* 賬號 -> 帳號
推匯 -> 推導

* Sync with main branch

* Update terminology.md

* 操作数量(num. of operations)-> 操作數量

* 字首和->前綴和

* Update figures

* 歸 -> 迴
記憶體洩漏 -> 記憶體流失

* Fix the bug of the file filter

* 支援 -> 支持
Add zh-Hant/README.md

* Add the zh-Hant chapter covers.
Bug fixes.

* 外掛 -> 擴充功能

* Add the landing page for zh-Hant version

* Unify the font of the chapter covers for the zh, en, and zh-Hant version

* Move zh-Hant/ to zh-hant/

* Translate terminology.md to traditional Chinese
This commit is contained in:
Yudong Jin
2024-04-06 02:30:11 +08:00
committed by GitHub
parent 33d7f8a2e5
commit 5f7385c8a3
1875 changed files with 102923 additions and 18 deletions
@@ -0,0 +1,146 @@
/**
* File: array_deque.dart
* Created Time: 2023-03-28
* Author: liuyuxin (gvenusleo@gmail.com)
*/
/* 基於環形陣列實現的雙向佇列 */
class ArrayDeque {
late List<int> _nums; // 用於儲存雙向佇列元素的陣列
late int _front; // 佇列首指標,指向佇列首元素
late int _queSize; // 雙向佇列長度
/* 建構子 */
ArrayDeque(int capacity) {
this._nums = List.filled(capacity, 0);
this._front = this._queSize = 0;
}
/* 獲取雙向佇列的容量 */
int capacity() {
return _nums.length;
}
/* 獲取雙向佇列的長度 */
int size() {
return _queSize;
}
/* 判斷雙向佇列是否為空 */
bool isEmpty() {
return _queSize == 0;
}
/* 計算環形陣列索引 */
int index(int i) {
// 透過取餘操作實現陣列首尾相連
// 當 i 越過陣列尾部後,回到頭部
// 當 i 越過陣列頭部後,回到尾部
return (i + capacity()) % capacity();
}
/* 佇列首入列 */
void pushFirst(int _num) {
if (_queSize == capacity()) {
throw Exception("雙向佇列已滿");
}
// 佇列首指標向左移動一位
// 透過取餘操作實現 _front 越過陣列頭部後回到尾部
_front = index(_front - 1);
// 將 _num 新增至佇列首
_nums[_front] = _num;
_queSize++;
}
/* 佇列尾入列 */
void pushLast(int _num) {
if (_queSize == capacity()) {
throw Exception("雙向佇列已滿");
}
// 計算佇列尾指標,指向佇列尾索引 + 1
int rear = index(_front + _queSize);
// 將 _num 新增至佇列尾
_nums[rear] = _num;
_queSize++;
}
/* 佇列首出列 */
int popFirst() {
int _num = peekFirst();
// 佇列首指標向右移動一位
_front = index(_front + 1);
_queSize--;
return _num;
}
/* 佇列尾出列 */
int popLast() {
int _num = peekLast();
_queSize--;
return _num;
}
/* 訪問佇列首元素 */
int peekFirst() {
if (isEmpty()) {
throw Exception("雙向佇列為空");
}
return _nums[_front];
}
/* 訪問佇列尾元素 */
int peekLast() {
if (isEmpty()) {
throw Exception("雙向佇列為空");
}
// 計算尾元素索引
int last = index(_front + _queSize - 1);
return _nums[last];
}
/* 返回陣列用於列印 */
List<int> toArray() {
// 僅轉換有效長度範圍內的串列元素
List<int> res = List.filled(_queSize, 0);
for (int i = 0, j = _front; i < _queSize; i++, j++) {
res[i] = _nums[index(j)];
}
return res;
}
}
/* Driver Code */
void main() {
/* 初始化雙向佇列 */
final ArrayDeque deque = ArrayDeque(10);
deque.pushLast(3);
deque.pushLast(2);
deque.pushLast(5);
print("雙向佇列 deque = ${deque.toArray()}");
/* 訪問元素 */
final int peekFirst = deque.peekFirst();
print("佇列首元素 peekFirst = $peekFirst");
final int peekLast = deque.peekLast();
print("佇列尾元素 peekLast = $peekLast");
/* 元素入列 */
deque.pushLast(4);
print("元素 4 佇列尾入列後 deque = ${deque.toArray()}");
deque.pushFirst(1);
print("元素 1 佇列首入列後 deque = ${deque.toArray()}");
/* 元素出列 */
final int popLast = deque.popLast();
print("佇列尾出列元素 = $popLast ,佇列尾出列後 deque = ${deque.toArray()}");
final int popFirst = deque.popFirst();
print("佇列首出列元素 = $popFirst ,佇列首出列後 deque = ${deque.toArray()}");
/* 獲取雙向佇列的長度 */
final int size = deque.size();
print("雙向佇列長度 size = $size");
/* 判斷雙向佇列是否為空 */
final bool isEmpty = deque.isEmpty();
print("雙向佇列是否為空 = $isEmpty");
}
@@ -0,0 +1,110 @@
/**
* File: array_queue.dart
* Created Time: 2023-03-28
* Author: liuyuxin (gvenusleo@gmail.com)
*/
/* 基於環形陣列實現的佇列 */
class ArrayQueue {
late List<int> _nums; // 用於儲存佇列元素的陣列
late int _front; // 佇列首指標,指向佇列首元素
late int _queSize; // 佇列長度
ArrayQueue(int capacity) {
_nums = List.filled(capacity, 0);
_front = _queSize = 0;
}
/* 獲取佇列的容量 */
int capaCity() {
return _nums.length;
}
/* 獲取佇列的長度 */
int size() {
return _queSize;
}
/* 判斷佇列是否為空 */
bool isEmpty() {
return _queSize == 0;
}
/* 入列 */
void push(int _num) {
if (_queSize == capaCity()) {
throw Exception("佇列已滿");
}
// 計算佇列尾指標,指向佇列尾索引 + 1
// 透過取餘操作實現 rear 越過陣列尾部後回到頭部
int rear = (_front + _queSize) % capaCity();
// 將 _num 新增至佇列尾
_nums[rear] = _num;
_queSize++;
}
/* 出列 */
int pop() {
int _num = peek();
// 佇列首指標向後移動一位,若越過尾部,則返回到陣列頭部
_front = (_front + 1) % capaCity();
_queSize--;
return _num;
}
/* 訪問佇列首元素 */
int peek() {
if (isEmpty()) {
throw Exception("佇列為空");
}
return _nums[_front];
}
/* 返回 Array */
List<int> toArray() {
// 僅轉換有效長度範圍內的串列元素
final List<int> res = List.filled(_queSize, 0);
for (int i = 0, j = _front; i < _queSize; i++, j++) {
res[i] = _nums[j % capaCity()];
}
return res;
}
}
/* Driver Code */
void main() {
/* 初始化佇列 */
final int capacity = 10;
final ArrayQueue queue = ArrayQueue(capacity);
/* 元素入列 */
queue.push(1);
queue.push(3);
queue.push(2);
queue.push(5);
queue.push(4);
print("佇列 queue = ${queue.toArray()}");
/* 訪問佇列首元素 */
final int peek = queue.peek();
print("佇列首元素 peek = $peek");
/* 元素出列 */
final int pop = queue.pop();
print("出列元素 pop = $pop ,出列後 queue = ${queue.toArray()}");
/* 獲取佇列長度 */
final int size = queue.size();
print("佇列長度 size = $size");
/* 判斷佇列是否為空 */
final bool isEmpty = queue.isEmpty();
print("佇列是否為空 = $isEmpty");
/* 測試環形陣列 */
for (int i = 0; i < 10; i++) {
queue.push(i);
queue.pop();
print("$i 輪入列 + 出列後 queue = ${queue.toArray()}");
}
}
@@ -0,0 +1,77 @@
/**
* File: array_stack.dart
* Created Time: 2023-03-28
* Author: liuyuxin (gvenusleo@gmail.com)
*/
/* 基於陣列實現的堆疊 */
class ArrayStack {
late List<int> _stack;
ArrayStack() {
_stack = [];
}
/* 獲取堆疊的長度 */
int size() {
return _stack.length;
}
/* 判斷堆疊是否為空 */
bool isEmpty() {
return _stack.isEmpty;
}
/* 入堆疊 */
void push(int _num) {
_stack.add(_num);
}
/* 出堆疊 */
int pop() {
if (isEmpty()) {
throw Exception("堆疊為空");
}
return _stack.removeLast();
}
/* 訪問堆疊頂元素 */
int peek() {
if (isEmpty()) {
throw Exception("堆疊為空");
}
return _stack.last;
}
/* 將堆疊轉化為 Array 並返回 */
List<int> toArray() => _stack;
}
/* Driver Code */
void main() {
/* 初始化堆疊 */
final ArrayStack stack = ArrayStack();
/* 元素入堆疊 */
stack.push(1);
stack.push(3);
stack.push(2);
stack.push(5);
stack.push(4);
print("堆疊 stack = ${stack.toArray()}");
/* 訪問堆疊頂元素 */
final int peek = stack.peek();
print("堆疊頂元素 peek = $peek");
/* 元素出堆疊 */
final int pop = stack.pop();
print("出堆疊元素 pop = $pop ,出堆疊後 stack = ${stack.toArray()}");
/* 獲取堆疊的長度 */
final int size = stack.size();
print("堆疊的長度 size = $size");
/* 判斷是否為空 */
final bool isEmpty = stack.isEmpty();
print("堆疊是否為空 = $isEmpty");
}
@@ -0,0 +1,42 @@
/**
* File: deque.dart
* Created Time: 2023-03-28
* Author: liuyuxin (gvenusleo@gmail.com)
*/
import 'dart:collection';
void main() {
/* 初始化雙向佇列 */
final Queue<int> deque = Queue();
deque.addFirst(3);
deque.addLast(2);
deque.addLast(5);
print("雙向佇列 deque = $deque");
/* 訪問元素 */
final int peekFirst = deque.first;
print("佇列首元素 peekFirst = $peekFirst");
final int peekLast = deque.last;
print("佇列尾元素 peekLast = $peekLast");
/* 元素入列 */
deque.addLast(4);
print("元素 4 佇列尾入列後 deque = $deque");
deque.addFirst(1);
print("元素 1 佇列首入列後 deque = $deque");
/* 元素出列 */
final int popLast = deque.removeLast();
print("佇列尾出列元素 = $popLast ,佇列尾出列後 deque = $deque");
final int popFirst = deque.removeFirst();
print("佇列首出列元素 = $popFirst ,佇列首出列後 deque = $deque");
/* 獲取雙向佇列的長度 */
final int size = deque.length;
print("雙向佇列長度 size = $size");
/* 判斷雙向佇列是否為空 */
final bool isEmpty = deque.isEmpty;
print("雙向佇列是否為空 = $isEmpty");
}
@@ -0,0 +1,167 @@
/**
* File: linkedlist_deque.dart
* Created Time: 2023-03-28
* Author: liuyuxin (gvenusleo@gmail.com)
*/
/* 雙向鏈結串列節點 */
class ListNode {
int val; // 節點值
ListNode? next; // 後繼節點引用
ListNode? prev; // 前驅節點引用
ListNode(this.val, {this.next, this.prev});
}
/* 基於雙向鏈結串列實現的雙向對列 */
class LinkedListDeque {
late ListNode? _front; // 頭節點 _front
late ListNode? _rear; // 尾節點 _rear
int _queSize = 0; // 雙向佇列的長度
LinkedListDeque() {
this._front = null;
this._rear = null;
}
/* 獲取雙向佇列長度 */
int size() {
return this._queSize;
}
/* 判斷雙向佇列是否為空 */
bool isEmpty() {
return size() == 0;
}
/* 入列操作 */
void push(int _num, bool isFront) {
final ListNode node = ListNode(_num);
if (isEmpty()) {
// 若鏈結串列為空,則令 _front 和 _rear 都指向 node
_front = _rear = node;
} else if (isFront) {
// 佇列首入列操作
// 將 node 新增至鏈結串列頭部
_front!.prev = node;
node.next = _front;
_front = node; // 更新頭節點
} else {
// 佇列尾入列操作
// 將 node 新增至鏈結串列尾部
_rear!.next = node;
node.prev = _rear;
_rear = node; // 更新尾節點
}
_queSize++; // 更新佇列長度
}
/* 佇列首入列 */
void pushFirst(int _num) {
push(_num, true);
}
/* 佇列尾入列 */
void pushLast(int _num) {
push(_num, false);
}
/* 出列操作 */
int? pop(bool isFront) {
// 若佇列為空,直接返回 null
if (isEmpty()) {
return null;
}
final int val;
if (isFront) {
// 佇列首出列操作
val = _front!.val; // 暫存頭節點值
// 刪除頭節點
ListNode? fNext = _front!.next;
if (fNext != null) {
fNext.prev = null;
_front!.next = null;
}
_front = fNext; // 更新頭節點
} else {
// 佇列尾出列操作
val = _rear!.val; // 暫存尾節點值
// 刪除尾節點
ListNode? rPrev = _rear!.prev;
if (rPrev != null) {
rPrev.next = null;
_rear!.prev = null;
}
_rear = rPrev; // 更新尾節點
}
_queSize--; // 更新佇列長度
return val;
}
/* 佇列首出列 */
int? popFirst() {
return pop(true);
}
/* 佇列尾出列 */
int? popLast() {
return pop(false);
}
/* 訪問佇列首元素 */
int? peekFirst() {
return _front?.val;
}
/* 訪問佇列尾元素 */
int? peekLast() {
return _rear?.val;
}
/* 返回陣列用於列印 */
List<int> toArray() {
ListNode? node = _front;
final List<int> res = [];
for (int i = 0; i < _queSize; i++) {
res.add(node!.val);
node = node.next;
}
return res;
}
}
/* Driver Code */
void main() {
/* 初始化雙向佇列 */
final LinkedListDeque deque = LinkedListDeque();
deque.pushLast(3);
deque.pushLast(2);
deque.pushLast(5);
print("雙向佇列 deque = ${deque.toArray()}");
/* 訪問元素 */
int? peekFirst = deque.peekFirst();
print("佇列首元素 peekFirst = $peekFirst");
int? peekLast = deque.peekLast();
print("佇列尾元素 peekLast = $peekLast");
/* 元素入列 */
deque.pushLast(4);
print("元素 4 佇列尾入列後 deque = ${deque.toArray()}");
deque.pushFirst(1);
print("元素 1 佇列首入列後 deque = ${deque.toArray()}");
/* 元素出列 */
int? popLast = deque.popLast();
print("佇列尾出列元素 = $popLast ,佇列尾出列後 deque = ${deque.toArray()}");
int? popFirst = deque.popFirst();
print("佇列首出列元素 = $popFirst ,佇列首出列後 deque = ${deque.toArray()}");
/* 獲取雙向佇列的長度 */
int size = deque.size();
print("雙向佇列長度 size = $size");
/* 判斷雙向佇列是否為空 */
bool isEmpty = deque.isEmpty();
print("雙向佇列是否為空 = $isEmpty");
}
@@ -0,0 +1,103 @@
/**
* File: linkedlist_queue.dart
* Created Time: 2023-03-28
* Author: liuyuxin (gvenusleo@gmail.com)
*/
import '../utils/list_node.dart';
/* 基於鏈結串列實現的佇列 */
class LinkedListQueue {
ListNode? _front; // 頭節點 _front
ListNode? _rear; // 尾節點 _rear
int _queSize = 0; // 佇列長度
LinkedListQueue() {
_front = null;
_rear = null;
}
/* 獲取佇列的長度 */
int size() {
return _queSize;
}
/* 判斷佇列是否為空 */
bool isEmpty() {
return _queSize == 0;
}
/* 入列 */
void push(int _num) {
// 在尾節點後新增 _num
final node = ListNode(_num);
// 如果佇列為空,則令頭、尾節點都指向該節點
if (_front == null) {
_front = node;
_rear = node;
} else {
// 如果佇列不為空,則將該節點新增到尾節點後
_rear!.next = node;
_rear = node;
}
_queSize++;
}
/* 出列 */
int pop() {
final int _num = peek();
// 刪除頭節點
_front = _front!.next;
_queSize--;
return _num;
}
/* 訪問佇列首元素 */
int peek() {
if (_queSize == 0) {
throw Exception('佇列為空');
}
return _front!.val;
}
/* 將鏈結串列轉化為 Array 並返回 */
List<int> toArray() {
ListNode? node = _front;
final List<int> queue = [];
while (node != null) {
queue.add(node.val);
node = node.next;
}
return queue;
}
}
/* Driver Code */
void main() {
/* 初始化佇列 */
final queue = LinkedListQueue();
/* 元素入列 */
queue.push(1);
queue.push(3);
queue.push(2);
queue.push(5);
queue.push(4);
print("佇列 queue = ${queue.toArray()}");
/* 訪問佇列首元素 */
final int peek = queue.peek();
print("佇列首元素 peek = $peek");
/* 元素出列 */
final int pop = queue.pop();
print("出列元素 pop = $pop ,出列後 queue = ${queue.toArray()}");
/* 獲取佇列的長度 */
final int size = queue.size();
print("佇列長度 size = $size");
/* 判斷佇列是否為空 */
final bool isEmpty = queue.isEmpty();
print("佇列是否為空 = $isEmpty");
}
@@ -0,0 +1,93 @@
/**
* File: linkedlist_stack.dart
* Created Time: 2023-03-27
* Author: liuyuxin (gvenusleo@gmail.com)
*/
import '../utils/list_node.dart';
/* 基於鏈結串列類別實現的堆疊 */
class LinkedListStack {
ListNode? _stackPeek; // 將頭節點作為堆疊頂
int _stkSize = 0; // 堆疊的長度
LinkedListStack() {
_stackPeek = null;
}
/* 獲取堆疊的長度 */
int size() {
return _stkSize;
}
/* 判斷堆疊是否為空 */
bool isEmpty() {
return _stkSize == 0;
}
/* 入堆疊 */
void push(int _num) {
final ListNode node = ListNode(_num);
node.next = _stackPeek;
_stackPeek = node;
_stkSize++;
}
/* 出堆疊 */
int pop() {
final int _num = peek();
_stackPeek = _stackPeek!.next;
_stkSize--;
return _num;
}
/* 訪問堆疊頂元素 */
int peek() {
if (_stackPeek == null) {
throw Exception("堆疊為空");
}
return _stackPeek!.val;
}
/* 將鏈結串列轉化為 List 並返回 */
List<int> toList() {
ListNode? node = _stackPeek;
List<int> list = [];
while (node != null) {
list.add(node.val);
node = node.next;
}
list = list.reversed.toList();
return list;
}
}
/* Driver Code */
void main() {
/* 初始化堆疊 */
final LinkedListStack stack = LinkedListStack();
/* 元素入堆疊 */
stack.push(1);
stack.push(3);
stack.push(2);
stack.push(5);
stack.push(4);
print("堆疊 stack = ${stack.toList()}");
/* 訪問堆疊頂元素 */
final int peek = stack.peek();
print("堆疊頂元素 peek = $peek");
/* 元素出堆疊 */
final int pop = stack.pop();
print("出堆疊元素 pop = $pop ,出堆疊後 stack = ${stack.toList()}");
/* 獲取堆疊的長度 */
final int size = stack.size();
print("堆疊的長度 size = $size");
/* 判斷是否為空 */
final bool isEmpty = stack.isEmpty();
print("堆疊是否為空 = $isEmpty");
}
@@ -0,0 +1,37 @@
/**
* File: queue.dart
* Created Time: 2023-03-28
* Author: liuyuxin (gvenusleo@gmail.com)
*/
import 'dart:collection';
void main() {
/* 初始化佇列 */
// 在 Dart 中,一般將雙向佇列類別 Queue 看作佇列使用
final Queue<int> queue = Queue();
/* 元素入列 */
queue.add(1);
queue.add(3);
queue.add(2);
queue.add(5);
queue.add(4);
print("佇列 queue = $queue");
/* 訪問佇列首元素 */
final int peek = queue.first;
print("佇列首元素 peek = $peek");
/* 元素出列 */
final int pop = queue.removeFirst();
print("出列元素 pop = $pop ,出列後 queue = $queue");
/* 獲取佇列長度 */
final int size = queue.length;
print("佇列長度 size = $size");
/* 判斷佇列是否為空 */
final bool isEmpty = queue.isEmpty;
print("佇列是否為空 = $isEmpty");
}
@@ -0,0 +1,35 @@
/**
* File: stack.dart
* Created Time: 2023-03-27
* Author: liuyuxin (gvenusleo@gmail.com)
*/
void main() {
/* 初始化堆疊 */
// Dart 沒有內建的堆疊類別,可以把 List 當作堆疊來使用
final List<int> stack = [];
/* 元素入堆疊 */
stack.add(1);
stack.add(3);
stack.add(2);
stack.add(5);
stack.add(4);
print("堆疊 stack = $stack");
/* 訪問堆疊頂元素 */
final int peek = stack.last;
print("堆疊頂元素 peek = $peek");
/* 元素出堆疊 */
final int pop = stack.removeLast();
print("出堆疊元素 pop = $pop ,出堆疊後 stack = $stack");
/* 獲取堆疊的長度 */
final int size = stack.length;
print("堆疊的長度 size = $size");
/* 判斷是否為空 */
final bool isEmpty = stack.isEmpty;
print("堆疊是否為空 = $isEmpty");
}