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

@@ -0,0 +1,4 @@
add_executable(utils
common.hpp print_utils.hpp
list_node.hpp tree_node.hpp
vertex.hpp)

View File

@@ -25,4 +25,4 @@
#include "tree_node.hpp"
#include "vertex.hpp"
using namespace std;
using namespace std;

View File

@@ -19,7 +19,7 @@ struct ListNode {
}
};
/* 配列を連結リストにシリアル化する */
/* リストを連結リストにシリアライズする */
ListNode *vecToLinkedList(vector<int> list) {
ListNode *dum = new ListNode(0);
ListNode *head = dum;
@@ -30,13 +30,13 @@ ListNode *vecToLinkedList(vector<int> list) {
return dum->next;
}
/* 連結リストに割り当てられたメモリを解放する */
/* 連結リストに割り当てたメモリを解放する */
void freeMemoryLinkedList(ListNode *cur) {
// メモリを解放
// メモリを解放する
ListNode *pre;
while (cur != nullptr) {
pre = cur;
cur = cur->next;
delete pre;
}
}
}

View File

@@ -13,7 +13,7 @@
#include <sstream>
#include <string>
/* ベクター内の要素を検索する */
/* Find an element in a vector */
template <typename T> int vecFind(const vector<T> &vec, T ele) {
int j = INT_MAX;
for (int i = 0; i < vec.size(); i++) {
@@ -24,7 +24,7 @@ template <typename T> int vecFind(const vector<T> &vec, T ele) {
return j;
}
/* ベクターを区切り文字で連結する */
/* Concatenate a vector with a delim */
template <typename T> string strJoin(const string &delim, const T &vec) {
ostringstream s;
for (const auto &i : vec) {
@@ -36,7 +36,7 @@ template <typename T> string strJoin(const string &delim, const T &vec) {
return s.str();
}
/* 文字列をn回繰り返す */
/* Repeat a string for n times */
string strRepeat(string str, int n) {
ostringstream os;
for (int i = 0; i < n; i++)
@@ -44,7 +44,7 @@ string strRepeat(string str, int n) {
return os.str();
}
/* 配列を印刷する */
/* 配列を出力する */
template <typename T> void printArray(T *arr, int n) {
cout << "[";
for (int i = 0; i < n - 1; i++) {
@@ -56,17 +56,17 @@ template <typename T> void printArray(T *arr, int n) {
cout << "]" << endl;
}
/* ベクター文字列オブジェクトを取得する */
/* Get the Vector String object */
template <typename T> string getVectorString(vector<T> &list) {
return "[" + strJoin(", ", list) + "]";
}
/* リストを印刷する */
/* リストを出力する */
template <typename T> void printVector(vector<T> list) {
cout << getVectorString(list) << '\n';
}
/* 行列を印刷する */
/* 行列を出力する */
template <typename T> void printVectorMatrix(vector<vector<T>> &matrix) {
cout << "[" << '\n';
for (vector<T> &list : matrix)
@@ -74,7 +74,7 @@ template <typename T> void printVectorMatrix(vector<vector<T>> &matrix) {
cout << "]" << '\n';
}
/* 連結リストを印刷する */
/* 連結リストを出力 */
void printLinkedList(ListNode *head) {
vector<int> list;
while (head != nullptr) {
@@ -104,8 +104,8 @@ void showTrunks(Trunk *p) {
}
/**
* 二分木を印刷する
* この木プリンターはTECHIE DELIGHTから借用しました
* 二分木を出力
* This tree printer is borrowed from TECHIE DELIGHT
* https://www.techiedelight.com/c-program-print-binary-tree/
*/
void printTree(TreeNode *root, Trunk *prev, bool isRight) {
@@ -139,20 +139,20 @@ void printTree(TreeNode *root, Trunk *prev, bool isRight) {
printTree(root->left, &trunk, false);
}
/* 二分木を印刷する */
/* 二分木を出力 */
void printTree(TreeNode *root) {
printTree(root, nullptr, false);
}
/* スタックを印刷する */
/* スタックを出力 */
template <typename T> void printStack(stack<T> stk) {
// 入力スタックを逆順にする
// Reverse the input stack
stack<T> tmp;
while (!stk.empty()) {
tmp.push(stk.top());
stk.pop();
}
// 印刷する文字列を生成
// Generate the string to print
ostringstream s;
bool flag = true;
while (!tmp.empty()) {
@@ -166,9 +166,9 @@ template <typename T> void printStack(stack<T> stk) {
cout << "[" + s.str() + "]" << '\n';
}
/* キューを印刷する */
/* キューを出力する */
template <typename T> void printQueue(queue<T> queue) {
// 印刷する文字列を生成
// Generate the string to print
ostringstream s;
bool flag = true;
while (!queue.empty()) {
@@ -182,9 +182,9 @@ template <typename T> void printQueue(queue<T> queue) {
cout << "[" + s.str() + "]" << '\n';
}
/* デックを印刷する */
/* 両端キューを出力する */
template <typename T> void printDeque(deque<T> deque) {
// 印刷する文字列を生成
// Generate the string to print
ostringstream s;
bool flag = true;
while (!deque.empty()) {
@@ -198,15 +198,15 @@ template <typename T> void printDeque(deque<T> deque) {
cout << "[" + s.str() + "]" << '\n';
}
/* ハッシュテーブルを印刷する */
// キー値ペアの型を指定するためテンプレートパラメータTKeyTValueを定義
/* ハッシュテーブルを出力 */
// キー値の型を指定するためテンプレート引数 TKeyTValue を定義
template <typename TKey, typename TValue> void printHashMap(unordered_map<TKey, TValue> map) {
for (auto kv : map) {
cout << kv.first << " -> " << kv.second << '\n';
}
}
/* priority_queueコンテナの基礎となるストレージを公開する */
/* Expose the underlying storage of the priority_queue container */
template <typename T, typename S, typename C> S &Container(priority_queue<T, S, C> &pq) {
struct HackedQueue : private priority_queue<T, S, C> {
static S &Container(priority_queue<T, S, C> &pq) {
@@ -216,13 +216,13 @@ template <typename T, typename S, typename C> S &Container(priority_queue<T, S,
return HackedQueue::Container(pq);
}
/* ヒープ(優先度付きキュー)を印刷する */
/* ヒープ(優先度付きキュー)を出力する */
template <typename T, typename S, typename C> void printHeap(priority_queue<T, S, C> &heap) {
vector<T> vec = Container(heap);
cout << "ヒープの配列表現:";
cout << "ヒープの配列表現";
printVector(vec);
cout << "ヒープの木表現:" << endl;
cout << "ヒープの木構造表現" << endl;
TreeNode *root = vectorToTree(vec);
printTree(root);
freeMemoryTree(root);
}
}

View File

@@ -11,7 +11,7 @@
using namespace std;
/* 二分木ノード構造 */
/* 二分木ノード構造 */
struct TreeNode {
int val{};
int height = 0;
@@ -23,23 +23,23 @@ struct TreeNode {
}
};
// シリアル化エンコーディング規則については以下を参照
// シリアライズの符号化規則は以下を参照:
// https://www.hello-algo.com/chapter_tree/array_representation_of_tree/
// 二分木の配列表現
// 二分木の配列表現:
// [1, 2, 3, 4, None, 6, 7, 8, 9, None, None, 12, None, None, 15]
// 二分木の連結リスト表現
// /——— 15
// /——— 7
// /——— 3
// | \——— 6
// | \——— 12
// 二分木の連結リスト表現:
// /——— 15
// /——— 7
// /——— 3
// | \——— 6
// | \——— 12
// ——— 1
// \——— 2
// | /——— 9
// \——— 4
// \——— 8
// \——— 2
// | /——— 9
// \——— 4
// \——— 8
/* 配列を二分木にシリアル化する:再帰 */
/* リストを二分木にシリアライズする: 再帰 */
TreeNode *vectorToTreeDFS(vector<int> &arr, int i) {
if (i < 0 || i >= arr.size() || arr[i] == INT_MAX) {
return nullptr;
@@ -50,12 +50,12 @@ TreeNode *vectorToTreeDFS(vector<int> &arr, int i) {
return root;
}
/* 配列を二分木にシリアル化する */
/* リストを二分木にシリアライズする */
TreeNode *vectorToTree(vector<int> arr) {
return vectorToTreeDFS(arr, 0);
}
/* 二分木を配列にシリアル化する:再帰 */
/* 二分木をリストにシリアライズする: 再帰 */
void treeToVecorDFS(TreeNode *root, int i, vector<int> &res) {
if (root == nullptr)
return;
@@ -67,18 +67,18 @@ void treeToVecorDFS(TreeNode *root, int i, vector<int> &res) {
treeToVecorDFS(root->right, 2 * i + 2, res);
}
/* 二分木を配列にシリアル化する */
/* 二分木をリストにシリアライズする */
vector<int> treeToVecor(TreeNode *root) {
vector<int> res;
treeToVecorDFS(root, 0, res);
return res;
}
/* 二分木に割り当てられたメモリを解放する */
/* 二分木メモリを解放する */
void freeMemoryTree(TreeNode *root) {
if (root == nullptr)
return;
freeMemoryTree(root->left);
freeMemoryTree(root->right);
delete root;
}
}

View File

@@ -17,7 +17,7 @@ struct Vertex {
}
};
/* 値リストvals を入力し、頂点リストvets を返す */
/* 値リスト vals を入力し、頂点リスト vets を返す */
vector<Vertex *> valsToVets(vector<int> vals) {
vector<Vertex *> vets;
for (int val : vals) {
@@ -26,11 +26,11 @@ vector<Vertex *> valsToVets(vector<int> vals) {
return vets;
}
/* 頂点リストvets を入力し、値リストvals を返す */
/* 頂点リスト vets を入力し、値リスト vals を返す */
vector<int> vetsToVals(vector<Vertex *> vets) {
vector<int> vals;
for (Vertex *vet : vets) {
vals.push_back(vet->val);
}
return vals;
}
}