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,121 @@
/**
* File: graph_adjacency_list.swift
* Created Time: 2023-02-01
* Author: nuomi1 (nuomi1@qq.com)
*/
import utils
/* */
public class GraphAdjList {
// keyvalue
public private(set) var adjList: [Vertex: [Vertex]]
/* */
public init(edges: [[Vertex]]) {
adjList = [:]
//
for edge in edges {
addVertex(vet: edge[0])
addVertex(vet: edge[1])
addEdge(vet1: edge[0], vet2: edge[1])
}
}
/* */
public func size() -> Int {
adjList.count
}
/* */
public func addEdge(vet1: Vertex, vet2: Vertex) {
if adjList[vet1] == nil || adjList[vet2] == nil || vet1 == vet2 {
fatalError("參數錯誤")
}
// vet1 - vet2
adjList[vet1]?.append(vet2)
adjList[vet2]?.append(vet1)
}
/* */
public func removeEdge(vet1: Vertex, vet2: Vertex) {
if adjList[vet1] == nil || adjList[vet2] == nil || vet1 == vet2 {
fatalError("參數錯誤")
}
// vet1 - vet2
adjList[vet1]?.removeAll { $0 == vet2 }
adjList[vet2]?.removeAll { $0 == vet1 }
}
/* */
public func addVertex(vet: Vertex) {
if adjList[vet] != nil {
return
}
//
adjList[vet] = []
}
/* */
public func removeVertex(vet: Vertex) {
if adjList[vet] == nil {
fatalError("參數錯誤")
}
// vet
adjList.removeValue(forKey: vet)
// vet
for key in adjList.keys {
adjList[key]?.removeAll { $0 == vet }
}
}
/* */
public func print() {
Swift.print("鄰接表 =")
for (vertex, list) in adjList {
let list = list.map { $0.val }
Swift.print("\(vertex.val): \(list),")
}
}
}
#if !TARGET
@main
enum GraphAdjacencyList {
/* Driver Code */
static func main() {
/* */
let v = Vertex.valsToVets(vals: [1, 3, 2, 5, 4])
let edges = [[v[0], v[1]], [v[0], v[3]], [v[1], v[2]], [v[2], v[3]], [v[2], v[4]], [v[3], v[4]]]
let graph = GraphAdjList(edges: edges)
print("\n初始化後,圖為")
graph.print()
/* */
// 1, 2 v[0], v[2]
graph.addEdge(vet1: v[0], vet2: v[2])
print("\n新增邊 1-2 後,圖為")
graph.print()
/* */
// 1, 3 v[0], v[1]
graph.removeEdge(vet1: v[0], vet2: v[1])
print("\n刪除邊 1-3 後,圖為")
graph.print()
/* */
let v5 = Vertex(val: 6)
graph.addVertex(vet: v5)
print("\n新增頂點 6 後,圖為")
graph.print()
/* */
// 3 v[1]
graph.removeVertex(vet: v[1])
print("\n刪除頂點 3 後,圖為")
graph.print()
}
}
#endif
@@ -0,0 +1,121 @@
/**
* File: graph_adjacency_list.swift
* Created Time: 2023-02-01
* Author: nuomi1 (nuomi1@qq.com)
*/
import utils
/* */
public class GraphAdjList {
// keyvalue
public private(set) var adjList: [Vertex: [Vertex]]
/* */
public init(edges: [[Vertex]]) {
adjList = [:]
//
for edge in edges {
addVertex(vet: edge[0])
addVertex(vet: edge[1])
addEdge(vet1: edge[0], vet2: edge[1])
}
}
/* */
public func size() -> Int {
adjList.count
}
/* */
public func addEdge(vet1: Vertex, vet2: Vertex) {
if adjList[vet1] == nil || adjList[vet2] == nil || vet1 == vet2 {
fatalError("參數錯誤")
}
// vet1 - vet2
adjList[vet1]?.append(vet2)
adjList[vet2]?.append(vet1)
}
/* */
public func removeEdge(vet1: Vertex, vet2: Vertex) {
if adjList[vet1] == nil || adjList[vet2] == nil || vet1 == vet2 {
fatalError("參數錯誤")
}
// vet1 - vet2
adjList[vet1]?.removeAll { $0 == vet2 }
adjList[vet2]?.removeAll { $0 == vet1 }
}
/* */
public func addVertex(vet: Vertex) {
if adjList[vet] != nil {
return
}
//
adjList[vet] = []
}
/* */
public func removeVertex(vet: Vertex) {
if adjList[vet] == nil {
fatalError("參數錯誤")
}
// vet
adjList.removeValue(forKey: vet)
// vet
for key in adjList.keys {
adjList[key]?.removeAll { $0 == vet }
}
}
/* */
public func print() {
Swift.print("鄰接表 =")
for (vertex, list) in adjList {
let list = list.map { $0.val }
Swift.print("\(vertex.val): \(list),")
}
}
}
#if !TARGET
@main
enum GraphAdjacencyList {
/* Driver Code */
static func main() {
/* */
let v = Vertex.valsToVets(vals: [1, 3, 2, 5, 4])
let edges = [[v[0], v[1]], [v[0], v[3]], [v[1], v[2]], [v[2], v[3]], [v[2], v[4]], [v[3], v[4]]]
let graph = GraphAdjList(edges: edges)
print("\n初始化後,圖為")
graph.print()
/* */
// 1, 2 v[0], v[2]
graph.addEdge(vet1: v[0], vet2: v[2])
print("\n新增邊 1-2 後,圖為")
graph.print()
/* */
// 1, 3 v[0], v[1]
graph.removeEdge(vet1: v[0], vet2: v[1])
print("\n刪除邊 1-3 後,圖為")
graph.print()
/* */
let v5 = Vertex(val: 6)
graph.addVertex(vet: v5)
print("\n新增頂點 6 後,圖為")
graph.print()
/* */
// 3 v[1]
graph.removeVertex(vet: v[1])
print("\n刪除頂點 3 後,圖為")
graph.print()
}
}
#endif
@@ -0,0 +1,130 @@
/**
* File: graph_adjacency_matrix.swift
* Created Time: 2023-02-01
* Author: nuomi1 (nuomi1@qq.com)
*/
import utils
/* */
class GraphAdjMat {
private var vertices: [Int] //
private var adjMat: [[Int]] //
/* */
init(vertices: [Int], edges: [[Int]]) {
self.vertices = []
adjMat = []
//
for val in vertices {
addVertex(val: val)
}
//
// edges vertices
for e in edges {
addEdge(i: e[0], j: e[1])
}
}
/* */
func size() -> Int {
vertices.count
}
/* */
func addVertex(val: Int) {
let n = size()
//
vertices.append(val)
//
let newRow = Array(repeating: 0, count: n)
adjMat.append(newRow)
//
for i in adjMat.indices {
adjMat[i].append(0)
}
}
/* */
func removeVertex(index: Int) {
if index >= size() {
fatalError("越界")
}
// index
vertices.remove(at: index)
// index
adjMat.remove(at: index)
// index
for i in adjMat.indices {
adjMat[i].remove(at: index)
}
}
/* */
// i, j vertices
func addEdge(i: Int, j: Int) {
//
if i < 0 || j < 0 || i >= size() || j >= size() || i == j {
fatalError("越界")
}
// 滿 (i, j) == (j, i)
adjMat[i][j] = 1
adjMat[j][i] = 1
}
/* */
// i, j vertices
func removeEdge(i: Int, j: Int) {
//
if i < 0 || j < 0 || i >= size() || j >= size() || i == j {
fatalError("越界")
}
adjMat[i][j] = 0
adjMat[j][i] = 0
}
/* */
func print() {
Swift.print("頂點串列 = ", terminator: "")
Swift.print(vertices)
Swift.print("鄰接矩陣 =")
PrintUtil.printMatrix(matrix: adjMat)
}
}
@main
enum GraphAdjacencyMatrix {
/* Driver Code */
static func main() {
/* */
// edges vertices
let vertices = [1, 3, 2, 5, 4]
let edges = [[0, 1], [1, 2], [2, 3], [0, 3], [2, 4], [3, 4]]
let graph = GraphAdjMat(vertices: vertices, edges: edges)
print("\n初始化後,圖為")
graph.print()
/* */
// 1, 2 0, 2
graph.addEdge(i: 0, j: 2)
print("\n新增邊 1-2 後,圖為")
graph.print()
/* */
// 1, 3 0, 1
graph.removeEdge(i: 0, j: 1)
print("\n刪除邊 1-3 後,圖為")
graph.print()
/* */
graph.addVertex(val: 6)
print("\n新增頂點 6 後,圖為")
graph.print()
/* */
// 3 1
graph.removeVertex(index: 1)
print("\n刪除頂點 3 後,圖為")
graph.print()
}
}
@@ -0,0 +1,56 @@
/**
* File: graph_bfs.swift
* Created Time: 2023-02-21
* Author: nuomi1 (nuomi1@qq.com)
*/
import graph_adjacency_list_target
import utils
/* */
// 使便
func graphBFS(graph: GraphAdjList, startVet: Vertex) -> [Vertex] {
//
var res: [Vertex] = []
//
var visited: Set<Vertex> = [startVet]
// BFS
var que: [Vertex] = [startVet]
// vet
while !que.isEmpty {
let vet = que.removeFirst() //
res.append(vet) //
//
for adjVet in graph.adjList[vet] ?? [] {
if visited.contains(adjVet) {
continue //
}
que.append(adjVet) //
visited.insert(adjVet) //
}
}
//
return res
}
@main
enum GraphBFS {
/* Driver Code */
static func main() {
/* */
let v = Vertex.valsToVets(vals: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
let edges = [
[v[0], v[1]], [v[0], v[3]], [v[1], v[2]], [v[1], v[4]],
[v[2], v[5]], [v[3], v[4]], [v[3], v[6]], [v[4], v[5]],
[v[4], v[7]], [v[5], v[8]], [v[6], v[7]], [v[7], v[8]],
]
let graph = GraphAdjList(edges: edges)
print("\n初始化後,圖為")
graph.print()
/* */
let res = graphBFS(graph: graph, startVet: v[0])
print("\n廣度優先走訪(BFS)頂點序列為")
print(Vertex.vetsToVals(vets: res))
}
}
@@ -0,0 +1,54 @@
/**
* File: graph_dfs.swift
* Created Time: 2023-02-21
* Author: nuomi1 (nuomi1@qq.com)
*/
import graph_adjacency_list_target
import utils
/* */
func dfs(graph: GraphAdjList, visited: inout Set<Vertex>, res: inout [Vertex], vet: Vertex) {
res.append(vet) //
visited.insert(vet) //
//
for adjVet in graph.adjList[vet] ?? [] {
if visited.contains(adjVet) {
continue //
}
//
dfs(graph: graph, visited: &visited, res: &res, vet: adjVet)
}
}
/* */
// 使便
func graphDFS(graph: GraphAdjList, startVet: Vertex) -> [Vertex] {
//
var res: [Vertex] = []
//
var visited: Set<Vertex> = []
dfs(graph: graph, visited: &visited, res: &res, vet: startVet)
return res
}
@main
enum GraphDFS {
/* Driver Code */
static func main() {
/* */
let v = Vertex.valsToVets(vals: [0, 1, 2, 3, 4, 5, 6])
let edges = [
[v[0], v[1]], [v[0], v[3]], [v[1], v[2]],
[v[2], v[5]], [v[4], v[5]], [v[5], v[6]],
]
let graph = GraphAdjList(edges: edges)
print("\n初始化後,圖為")
graph.print()
/* */
let res = graphDFS(graph: graph, startVet: v[0])
print("\n深度優先走訪(DFS)頂點序列為")
print(Vertex.vetsToVals(vets: res))
}
}