Re-translate the Japanese version (#1871)

* Retranslate Japanese docs with GPT-5.4

* Retranslate Japanese code with GPT-5.4
This commit is contained in:
Yudong Jin
2026-03-30 07:30:15 +08:00
committed by GitHub
parent fe6443235b
commit d7b2277d2b
1444 changed files with 83312 additions and 8363 deletions

View File

@@ -6,7 +6,7 @@
#include "../utils/common.hpp"
/* 配列ベースの二分木クラス */
/* 配列表現による二分木クラス */
class ArrayBinaryTree {
public:
/* コンストラクタ */
@@ -14,30 +14,30 @@ class ArrayBinaryTree {
tree = arr;
}
/* リスト容量 */
/* リスト容量 */
int size() {
return tree.size();
}
/* インデックス i のノードの値を取得 */
int val(int i) {
// インデックスが範囲外の場合、INT_MAX を返すnull を表す)
// インデックスが範囲外なら、空きを表す INT_MAX を返す
if (i < 0 || i >= size())
return INT_MAX;
return tree[i];
}
/* インデックス i のノードの左子のインデックスを取得 */
/* インデックス i のノードの左子ノードのインデックスを取得 */
int left(int i) {
return 2 * i + 1;
}
/* インデックス i のノードの右子のインデックスを取得 */
/* インデックス i のノードの右子ノードのインデックスを取得 */
int right(int i) {
return 2 * i + 2;
}
/* インデックス i のノードの親のインデックスを取得 */
/* インデックス i のノードの親ノードのインデックスを取得 */
int parent(int i) {
return (i - 1) / 2;
}
@@ -45,7 +45,7 @@ class ArrayBinaryTree {
/* レベル順走査 */
vector<int> levelOrder() {
vector<int> res;
// 配列を走査
// 配列を直接走査する
for (int i = 0; i < size(); i++) {
if (val(i) != INT_MAX)
res.push_back(val(i));
@@ -53,7 +53,7 @@ class ArrayBinaryTree {
return res;
}
/* 順走査 */
/* 先行順走査 */
vector<int> preOrder() {
vector<int> res;
dfs(0, "pre", res);
@@ -77,12 +77,12 @@ class ArrayBinaryTree {
private:
vector<int> tree;
/* 深さ優先走査 */
/* 深さ優先探索 */
void dfs(int i, string order, vector<int> &res) {
// 空の位置の場合、戻る
// 空きスロットなら返す
if (val(i) == INT_MAX)
return;
// 順走査
// 先行順走査
if (order == "pre")
res.push_back(val(i));
dfs(left(i), order, res);
@@ -96,42 +96,42 @@ class ArrayBinaryTree {
}
};
/* ドライバーコード */
/* Driver Code */
int main() {
// 二分木を初期化
// INT_MAX を使用して空の位置 nullptr を表す
// 二分木を初期化する
// 空き位置 nullptr は INT_MAX で表す
vector<int> arr = {1, 2, 3, 4, INT_MAX, 6, 7, 8, 9, INT_MAX, INT_MAX, 12, INT_MAX, INT_MAX, 15};
TreeNode *root = vectorToTree(arr);
cout << "\n二分木を初期化\n";
cout << "二分木の配列表現:\n";
cout << "二分木の配列表現\n";
printVector(arr);
cout << "二分木の連結リスト表現:\n";
cout << "二分木の連結リスト表現\n";
printTree(root);
// 配列ベースの二分木クラス
// 配列表現による二分木クラス
ArrayBinaryTree abt(arr);
// ノードにアクセス
int i = 1;
int l = abt.left(i), r = abt.right(i), p = abt.parent(i);
cout << "\n現在のノードのインデックスは " << i << "、値 = " << abt.val(i) << "\n";
cout << "その左の子のインデックスは " << l << "、値 = " << (l != INT_MAX ? to_string(abt.val(l)) : "nullptr") << "\n";
cout << "その右の子のインデックスは " << r << "、値 = " << (r != INT_MAX ? to_string(abt.val(r)) : "nullptr") << "\n";
cout << "その親のインデックスは " << p << "、値 = " << (p != INT_MAX ? to_string(abt.val(p)) : "nullptr") << "\n";
cout << "\n現在のノードのインデックスは " << i << "、値 " << abt.val(i) << "\n";
cout << "左の子ノードのインデックスは " << l << "、値 " << (abt.val(l) != INT_MAX ? to_string(abt.val(l)) : "nullptr") << "\n";
cout << "右の子ノードのインデックスは " << r << "、値 " << (abt.val(r) != INT_MAX ? to_string(abt.val(r)) : "nullptr") << "\n";
cout << "ノードのインデックスは " << p << "、値 " << (abt.val(p) != INT_MAX ? to_string(abt.val(p)) : "nullptr") << "\n";
// 木を走査
vector<int> res = abt.levelOrder();
cout << "\nレベル順走査は:";
cout << "\nレベル順走査 ";
printVector(res);
res = abt.preOrder();
cout << "順走査は:";
cout << "先行順走査 ";
printVector(res);
res = abt.inOrder();
cout << "中順走査は:";
cout << "順走査 ";
printVector(res);
res = abt.postOrder();
cout << "後順走査は:";
cout << "順走査 ";
printVector(res);
return 0;
}
}