Retranslate the complete Japanese online edition from Chinese (#2008)

* Retranslate the complete Japanese online edition from Chinese

* Fit Japanese homepage labels and localize heading permalinks

* Point Japanese contribution instructions to the Japanese preview

* Replace locale conditionals with multilingual UI tables
This commit is contained in:
Yudong Jin
2026-10-30 02:12:26 +08:00
committed by GitHub
parent 455e8c1281
commit 7257641e0e
1987 changed files with 23531 additions and 23261 deletions
@@ -6,15 +6,15 @@
const { Vertex } = require('../modules/Vertex');
/* 隣接リストに基づく無向グラフクラス */
/* 隣接リストで実装した無向グラフクラス */
class GraphAdjList {
// 隣接リスト。key は頂点、value はその頂点に隣接する全頂点
// 隣接リスト。key:頂点、value:その頂点に隣接する全頂点
adjList;
/* コンストラクタ */
constructor(edges) {
this.adjList = new Map();
// すべての頂点と辺を追加
// すべての頂点と辺を追加する
for (const edge of edges) {
this.addVertex(edge[0]);
this.addVertex(edge[1]);
@@ -22,26 +22,26 @@ class GraphAdjList {
}
}
/* 頂点数を取得 */
/* 頂点数を取得する */
size() {
return this.adjList.size;
}
/* 辺を追加 */
/* 辺を追加する */
addEdge(vet1, vet2) {
if (
!this.adjList.has(vet1) ||
!this.adjList.has(vet2) ||
vet1 === vet2
) {
throw new Error('Illegal Argument Exception');
throw new Error('不正な引数の例外');
}
// 辺 vet1 - vet2 を追加
// 辺 vet1 - vet2 を追加する
this.adjList.get(vet1).push(vet2);
this.adjList.get(vet2).push(vet1);
}
/* 辺を削除 */
/* 辺を削除する */
removeEdge(vet1, vet2) {
if (
!this.adjList.has(vet1) ||
@@ -49,28 +49,28 @@ class GraphAdjList {
vet1 === vet2 ||
this.adjList.get(vet1).indexOf(vet2) === -1
) {
throw new Error('Illegal Argument Exception');
throw new Error('不正な引数の例外');
}
// 辺 vet1 - vet2 を削除
// 辺 vet1 - vet2 を削除する
this.adjList.get(vet1).splice(this.adjList.get(vet1).indexOf(vet2), 1);
this.adjList.get(vet2).splice(this.adjList.get(vet2).indexOf(vet1), 1);
}
/* 頂点を追加 */
/* 頂点を追加する */
addVertex(vet) {
if (this.adjList.has(vet)) return;
// 隣接リストに新しいリストを追加
// 隣接リストに新しい連結リストを追加する
this.adjList.set(vet, []);
}
/* 頂点を削除 */
/* 頂点を削除する */
removeVertex(vet) {
if (!this.adjList.has(vet)) {
throw new Error('Illegal Argument Exception');
throw new Error('不正な引数の例外');
}
// 隣接リストから頂点 vet に対応するリストを削除
// 隣接リストから頂点 vet に対応する連結リストを削除する
this.adjList.delete(vet);
// 他の頂点のリストを走査し、vet を含むすべての辺を削除
// 他の頂点の連結リストを走査し、vet を含むすべての辺を削除する
for (const set of this.adjList.values()) {
const index = set.indexOf(vet);
if (index > -1) {
@@ -79,7 +79,7 @@ class GraphAdjList {
}
}
/* 隣接リストを出力 */
/* 隣接リストを表示する */
print() {
console.log('隣接リスト =');
for (const [key, value] of this.adjList) {
@@ -93,8 +93,8 @@ class GraphAdjList {
}
if (require.main === module) {
/* Driver Code */
/* 無向グラフを初期化 */
/* 実行用コード */
/* 無向グラフを初期化する */
const v0 = new Vertex(1),
v1 = new Vertex(3),
v2 = new Vertex(2),
@@ -109,31 +109,31 @@ if (require.main === module) {
[v3, v4],
];
const graph = new GraphAdjList(edges);
console.log('\n初期化後のグラフは');
console.log('\n初期化後のグラフ');
graph.print();
/* 辺を追加 */
// 頂点 1, 2 は v0, v2
/* 辺を追加する */
// 頂点 1, 2 は v0, v2 に対応する
graph.addEdge(v0, v2);
console.log('\n辺 1-2 を追加した後のグラフは');
console.log('\n辺 1-2 を追加した後のグラフ');
graph.print();
/* 辺を削除 */
// 頂点 1, 3 は v0, v1
/* 辺を削除する */
// 頂点 1, 3 は v0, v1 に対応する
graph.removeEdge(v0, v1);
console.log('\n辺 1-3 を削除した後のグラフは');
console.log('\n辺 1-3 を削除した後のグラフ');
graph.print();
/* 頂点を追加 */
/* 頂点を追加する */
const v5 = new Vertex(6);
graph.addVertex(v5);
console.log('\n頂点 6 を追加した後のグラフは');
console.log('\n頂点 6 を追加した後のグラフ');
graph.print();
/* 頂点を削除 */
// 頂点 3 は v1
/* 頂点を削除する */
// 頂点 3 は v1 に対応する
graph.removeVertex(v1);
console.log('\n頂点 3 を削除した後のグラフは');
console.log('\n頂点 3 を削除した後のグラフ');
graph.print();
}
@@ -4,97 +4,97 @@
* Author: Zhuo Qinyue ([email protected])
*/
/* 隣接行列に基づく無向グラフクラス */
/* 隣接行列で実装した無向グラフクラス */
class GraphAdjMat {
vertices; // 頂点リスト。要素は「頂点値」、インデックスは「頂点インデックス」を表す
adjMat; // 隣接行列。行・列のインデックスは「頂点インデックス」に対応
vertices; // 頂点リスト。要素は「頂点の値」、インデックスは「頂点のインデックス」を表す
adjMat; // 隣接行列。行と列のインデックスは「頂点のインデックス」に対応する
/* コンストラクタ */
constructor(vertices, edges) {
this.vertices = [];
this.adjMat = [];
// 頂点を追加
// 頂点を追加する
for (const val of vertices) {
this.addVertex(val);
}
// 辺を追加
// 注意:edges の各要素は頂点インデックスを表し、vertices の要素インデックスに対応する
// 辺を追加する
// edges の要素は頂点のインデックス、すなわち vertices の要素のインデックスを表すことに注意
for (const e of edges) {
this.addEdge(e[0], e[1]);
}
}
/* 頂点数を取得 */
/* 頂点数を取得する */
size() {
return this.vertices.length;
}
/* 頂点を追加 */
/* 頂点を追加する */
addVertex(val) {
const n = this.size();
// 頂点リストに新しい頂点の値を追加
// 頂点リストに新しい頂点の値を追加する
this.vertices.push(val);
// 隣接行列に 1 行追加
// 隣接行列に 1 行追加する
const newRow = [];
for (let j = 0; j < n; j++) {
newRow.push(0);
}
this.adjMat.push(newRow);
// 隣接行列に 1 列追加
// 隣接行列に 1 列追加する
for (const row of this.adjMat) {
row.push(0);
}
}
/* 頂点を削除 */
/* 頂点を削除する */
removeVertex(index) {
if (index >= this.size()) {
throw new RangeError('Index Out Of Bounds Exception');
throw new RangeError('インデックス範囲外の例外');
}
// 頂点リストから index の頂点を削除する
// 頂点リストからインデックス index の頂点を削除する
this.vertices.splice(index, 1);
// 隣接行列で index 行を削除する
// 隣接行列からインデックス index の行を削除する
this.adjMat.splice(index, 1);
// 隣接行列で index 列を削除する
// 隣接行列からインデックス index の列を削除する
for (const row of this.adjMat) {
row.splice(index, 1);
}
}
/* 辺を追加 */
// 引数 i, j は vertices の要素インデックスに対応する
/* 辺を追加する */
// 引数 i, j は vertices の要素のインデックスに対応する
addEdge(i, j) {
// インデックスの範囲外と等値の処理
// 添字が範囲外または互いに等しい場合の処理
if (i < 0 || j < 0 || i >= this.size() || j >= this.size() || i === j) {
throw new RangeError('Index Out Of Bounds Exception');
throw new RangeError('インデックス範囲外の例外');
}
// 無向グラフでは、隣接行列は主対角線に関して対称であり、(i, j) === (j, i) を満たす
// 無向グラフの隣接行列は主対角線に関して対称であり、(i, j) === (j, i) を満たす
this.adjMat[i][j] = 1;
this.adjMat[j][i] = 1;
}
/* 辺を削除 */
// 引数 i, j は vertices の要素インデックスに対応する
/* 辺を削除する */
// 引数 i, j は vertices の要素のインデックスに対応する
removeEdge(i, j) {
// インデックスの範囲外と等値の処理
// 添字が範囲外または互いに等しい場合の処理
if (i < 0 || j < 0 || i >= this.size() || j >= this.size() || i === j) {
throw new RangeError('Index Out Of Bounds Exception');
throw new RangeError('インデックス範囲外の例外');
}
this.adjMat[i][j] = 0;
this.adjMat[j][i] = 0;
}
/* 隣接行列を出力 */
/* 隣接行列を表示する */
print() {
console.log('頂点リスト = ', this.vertices);
console.log('隣接行列 =', this.adjMat);
}
}
/* Driver Code */
/* 無向グラフを初期化 */
// edges の要素は頂点インデックス、すなわち vertices の要素インデックスに対応する点に注意
/* 実行用コード */
/* 無向グラフを初期化する */
// edges の要素は頂点のインデックス、すなわち vertices の要素のインデックスを表すことに注意
const vertices = [1, 3, 2, 5, 4];
const edges = [
[0, 1],
@@ -105,28 +105,28 @@ const edges = [
[3, 4],
];
const graph = new GraphAdjMat(vertices, edges);
console.log('\n初期化後のグラフは');
console.log('\n初期化後のグラフ');
graph.print();
/* 辺を追加 */
/* 辺を追加する */
// 頂点 1, 2 のインデックスはそれぞれ 0, 2
graph.addEdge(0, 2);
console.log('\n辺 1-2 を追加した後のグラフは');
console.log('\n辺 1-2 を追加した後のグラフ');
graph.print();
/* 辺を削除 */
/* 辺を削除する */
// 頂点 1, 3 のインデックスはそれぞれ 0, 1
graph.removeEdge(0, 1);
console.log('\n辺 1-3 を削除した後のグラフは');
console.log('\n辺 1-3 を削除した後のグラフ');
graph.print();
/* 頂点を追加 */
/* 頂点を追加する */
graph.addVertex(6);
console.log('\n頂点 6 を追加した後のグラフは');
console.log('\n頂点 6 を追加した後のグラフ');
graph.print();
/* 頂点を削除 */
/* 頂点を削除する */
// 頂点 3 のインデックスは 1
graph.removeVertex(1);
console.log('\n頂点 3 を削除した後のグラフは');
console.log('\n頂点 3 を削除した後のグラフ');
graph.print();
+16 -16
View File
@@ -7,35 +7,35 @@
const { GraphAdjList } = require('./graph_adjacency_list');
const { Vertex } = require('../modules/Vertex');
/* 幅優先探索 */
// グラフを隣接リストで表し、指定した頂点の隣接頂点をすべて取得できるようにする
/* 幅優先走査 */
// 指定した頂点に隣接する全頂点を取得しやすいように、グラフを隣接リストで表す
function graphBFS(graph, startVet) {
// 頂点の走査順序
const res = [];
// 訪問済み頂点を記録するためのハッシュ集合
// 訪問済みの頂点を記録するハッシュ集合
const visited = new Set();
visited.add(startVet);
// BFS の実装にキューを用いる
// BFS の実装にキューを使う
const que = [startVet];
// 頂点 vet を起点に、すべての頂点を訪問し終えるまで繰り返す
// 頂点 vet を始点として、すべての頂点を訪問するまで繰り返す
while (que.length) {
const vet = que.shift(); // 先頭の頂点をデキュー
res.push(vet); // 訪問した頂点を記録
// この頂点のすべての隣接頂点を走査
const vet = que.shift(); // キューの先頭の頂点をデキューする
res.push(vet); // 訪問した頂点を記録する
// この頂点に隣接する全頂点を走査する
for (const adjVet of graph.adjList.get(vet) ?? []) {
if (visited.has(adjVet)) {
continue; // 訪問済みの頂点をスキップ
continue; // 訪問済みの頂点をスキップする
}
que.push(adjVet); // 未訪問の頂点のみをキューに追加
que.push(adjVet); // 未訪問の頂点だけをエンキューする
visited.add(adjVet); // この頂点を訪問済みにする
}
}
// 頂点の走査順を返す
// 頂点の走査順序を返す
return res;
}
/* Driver Code */
/* 無向グラフを初期化 */
/* 実行用コード */
/* 無向グラフを初期化する */
const v = Vertex.valsToVets([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
const edges = [
[v[0], v[1]],
@@ -52,10 +52,10 @@ const edges = [
[v[7], v[8]],
];
const graph = new GraphAdjList(edges);
console.log('\n初期化後のグラフは');
console.log('\n初期化後のグラフ');
graph.print();
/* 幅優先探索 */
/* 幅優先走査 */
const res = graphBFS(graph, v[0]);
console.log('\n幅優先探索(BFS)の頂点列は');
console.log('\n幅優先走査(BFS)の頂点の順序');
console.log(Vertex.vetsToVals(res));
+14 -14
View File
@@ -7,34 +7,34 @@
const { Vertex } = require('../modules/Vertex');
const { GraphAdjList } = require('./graph_adjacency_list');
/* 深さ優先探索 */
// グラフを隣接リストで表し、指定した頂点の隣接頂点をすべて取得できるようにする
/* 深さ優先走査 */
// 指定した頂点に隣接する全頂点を取得しやすいように、グラフを隣接リストで表す
function dfs(graph, visited, res, vet) {
res.push(vet); // 訪問した頂点を記録
res.push(vet); // 訪問した頂点を記録する
visited.add(vet); // この頂点を訪問済みにする
// この頂点のすべての隣接頂点を走査
// この頂点に隣接する全頂点を走査する
for (const adjVet of graph.adjList.get(vet)) {
if (visited.has(adjVet)) {
continue; // 訪問済みの頂点をスキップ
continue; // 訪問済みの頂点をスキップする
}
// 隣接頂点を再帰的に訪問
// 隣接する頂点を再帰的に訪問する
dfs(graph, visited, res, adjVet);
}
}
/* 深さ優先探索 */
// グラフを隣接リストで表し、指定した頂点の隣接頂点をすべて取得できるようにする
/* 深さ優先走査 */
// 指定した頂点に隣接する全頂点を取得しやすいように、グラフを隣接リストで表す
function graphDFS(graph, startVet) {
// 頂点の走査順序
const res = [];
// 訪問済み頂点を記録するためのハッシュ集合
// 訪問済みの頂点を記録するハッシュ集合
const visited = new Set();
dfs(graph, visited, res, startVet);
return res;
}
/* Driver Code */
/* 無向グラフを初期化 */
/* 実行用コード */
/* 無向グラフを初期化する */
const v = Vertex.valsToVets([0, 1, 2, 3, 4, 5, 6]);
const edges = [
[v[0], v[1]],
@@ -45,10 +45,10 @@ const edges = [
[v[5], v[6]],
];
const graph = new GraphAdjList(edges);
console.log('\n初期化後のグラフは');
console.log('\n初期化後のグラフ');
graph.print();
/* 深さ優先探索 */
/* 深さ優先走査 */
const res = graphDFS(graph, v[0]);
console.log('\n深さ優先探索(DFS)の頂点列は');
console.log('\n深さ優先走査(DFS)の頂点の順序');
console.log(Vertex.vetsToVals(res));