mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-02 11:15:19 +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:
@@ -8,34 +8,34 @@
|
||||
|
||||
/* レベル順走査 */
|
||||
vector<int> levelOrder(TreeNode *root) {
|
||||
// キューを初期化し、ルートノードを追加する
|
||||
// キューを初期化し、根ノードを追加する
|
||||
queue<TreeNode *> queue;
|
||||
queue.push(root);
|
||||
// 走査順序を保存するためのリストを初期化する
|
||||
// 走査順序を保存するリストを初期化する
|
||||
vector<int> vec;
|
||||
while (!queue.empty()) {
|
||||
TreeNode *node = queue.front();
|
||||
queue.pop(); // デキュー
|
||||
queue.pop(); // キューからデキューする
|
||||
vec.push_back(node->val); // ノードの値を保存する
|
||||
if (node->left != nullptr)
|
||||
queue.push(node->left); // 左子ノードをキューに追加
|
||||
queue.push(node->left); // 左の子ノードをエンキューする
|
||||
if (node->right != nullptr)
|
||||
queue.push(node->right); // 右子ノードをキューに追加
|
||||
queue.push(node->right); // 右の子ノードをエンキューする
|
||||
}
|
||||
return vec;
|
||||
}
|
||||
|
||||
/* Driver Code */
|
||||
/* 実行用コード */
|
||||
int main() {
|
||||
/* 二分木を初期化 */
|
||||
// ここでは、配列から直接二分木を生成する関数を利用する
|
||||
/* 二分木を初期化する */
|
||||
// ここでは配列から二分木を直接生成する関数を使う
|
||||
TreeNode *root = vectorToTree(vector<int>{1, 2, 3, 4, 5, 6, 7});
|
||||
cout << endl << "二分木を初期化\n" << endl;
|
||||
cout << endl << "二分木を初期化する\n" << endl;
|
||||
printTree(root);
|
||||
|
||||
/* レベル順走査 */
|
||||
vector<int> vec = levelOrder(root);
|
||||
cout << endl << "レベル順走査のノード出力列 = ";
|
||||
cout << endl << "レベル順走査で表示するノードの順序 = ";
|
||||
printVector(vec);
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user