mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-06 21:22:10 +08:00
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:
@@ -11,7 +11,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* 連結リストノード */
|
||||
/* 連結リストのノード */
|
||||
struct ListNode {
|
||||
int val;
|
||||
ListNode *next;
|
||||
@@ -19,7 +19,7 @@ struct ListNode {
|
||||
}
|
||||
};
|
||||
|
||||
/* リストを連結リストにデシリアライズする */
|
||||
/* リストをデシリアライズして連結リストにする */
|
||||
ListNode *vecToLinkedList(vector<int> list) {
|
||||
ListNode *dum = new ListNode(0);
|
||||
ListNode *head = dum;
|
||||
@@ -30,7 +30,7 @@ ListNode *vecToLinkedList(vector<int> list) {
|
||||
return dum->next;
|
||||
}
|
||||
|
||||
/* 連結リストに割り当てたメモリを解放する */
|
||||
/* 連結リストに確保したメモリ領域を解放する */
|
||||
void freeMemoryLinkedList(ListNode *cur) {
|
||||
// メモリを解放する
|
||||
ListNode *pre;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
/* Find an element in a vector */
|
||||
/* 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 */
|
||||
/* vector の要素を区切り文字で連結する */
|
||||
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();
|
||||
}
|
||||
|
||||
/* Repeat a string for n times */
|
||||
/* 文字列を n 回繰り返す */
|
||||
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 */
|
||||
/* vector の文字列表現を取得する */
|
||||
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) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 二分木を出力
|
||||
* This tree printer is borrowed from TECHIE DELIGHT
|
||||
* 二分木を表示する
|
||||
* この木の表示処理は 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';
|
||||
}
|
||||
|
||||
/* ハッシュテーブルを出力 */
|
||||
// キーと値の型を指定するためのテンプレート引数 TKey と TValue を定義
|
||||
/* ハッシュテーブルを表示する */
|
||||
// キーと値のペアの型を指定するテンプレート引数 TKey と TValue を定義する
|
||||
template <typename TKey, typename TValue> void printHashMap(unordered_map<TKey, TValue> map) {
|
||||
for (auto kv : map) {
|
||||
cout << kv.first << " -> " << kv.second << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
/* Expose the underlying storage of the priority_queue container */
|
||||
/* priority_queue コンテナの内部ストレージを公開する */
|
||||
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,7 +216,7 @@ 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 << "ヒープの配列表現:";
|
||||
|
||||
@@ -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/
|
||||
// 二分木の配列表現:
|
||||
// シリアライズの符号化規則は次を参照:
|
||||
// https://www.hello-algo.com/ja/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,7 +67,7 @@ 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);
|
||||
|
||||
@@ -17,7 +17,7 @@ struct Vertex {
|
||||
}
|
||||
};
|
||||
|
||||
/* 値リスト vals を入力し、頂点リスト vets を返す */
|
||||
/* 値のリスト vals を入力し、頂点のリスト vets を返す */
|
||||
vector<Vertex *> valsToVets(vector<int> vals) {
|
||||
vector<Vertex *> vets;
|
||||
for (int val : vals) {
|
||||
@@ -26,7 +26,7 @@ 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) {
|
||||
|
||||
Reference in New Issue
Block a user