mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-04 12:12:45 +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:
@@ -9,26 +9,26 @@ const { printTree } = require('../modules/PrintUtil');
|
||||
|
||||
/* レベル順走査 */
|
||||
function levelOrder(root) {
|
||||
// キューを初期化し、ルートノードを追加する
|
||||
// キューを初期化し、根ノードを追加する
|
||||
const queue = [root];
|
||||
// 走査順序を保存するためのリストを初期化する
|
||||
// 走査順序を保存するリストを初期化する
|
||||
const list = [];
|
||||
while (queue.length) {
|
||||
let node = queue.shift(); // デキュー
|
||||
let node = queue.shift(); // キューからデキューする
|
||||
list.push(node.val); // ノードの値を保存する
|
||||
if (node.left) queue.push(node.left); // 左子ノードをキューに追加
|
||||
if (node.right) queue.push(node.right); // 右子ノードをキューに追加
|
||||
if (node.left) queue.push(node.left); // 左の子ノードをエンキューする
|
||||
if (node.right) queue.push(node.right); // 右の子ノードをエンキューする
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/* Driver Code */
|
||||
/* 二分木を初期化 */
|
||||
// ここでは、配列から直接二分木を生成する関数を利用する
|
||||
/* 実行用コード */
|
||||
/* 二分木を初期化する */
|
||||
// ここでは配列から二分木を直接生成する関数を使う
|
||||
const root = arrToTree([1, 2, 3, 4, 5, 6, 7]);
|
||||
console.log('\n二分木を初期化\n');
|
||||
console.log('\n二分木を初期化する\n');
|
||||
printTree(root);
|
||||
|
||||
/* レベル順走査 */
|
||||
const list = levelOrder(root);
|
||||
console.log('\nレベル順走査のノード出力シーケンス = ' + list);
|
||||
console.log('\nレベル順走査で表示するノードの順序 = ' + list);
|
||||
|
||||
Reference in New Issue
Block a user