mirror of
https://github.com/krahets/hello-algo.git
synced 2026-06-28 08:34:28 +00:00
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:
@@ -13,11 +13,11 @@ public class binary_tree_dfs {
|
||||
// 走査順序を格納するリストを初期化
|
||||
static ArrayList<Integer> list = new ArrayList<>();
|
||||
|
||||
/* 前順走査 */
|
||||
/* 先行順走査 */
|
||||
static void preOrder(TreeNode root) {
|
||||
if (root == null)
|
||||
return;
|
||||
// 訪問優先度: 根ノード -> 左部分木 -> 右部分木
|
||||
// 訪問順序:根ノード -> 左部分木 -> 右部分木
|
||||
list.add(root.val);
|
||||
preOrder(root.left);
|
||||
preOrder(root.right);
|
||||
@@ -27,7 +27,7 @@ public class binary_tree_dfs {
|
||||
static void inOrder(TreeNode root) {
|
||||
if (root == null)
|
||||
return;
|
||||
// 訪問優先度: 左部分木 -> 根ノード -> 右部分木
|
||||
// 訪問優先順: 左部分木 -> 根ノード -> 右部分木
|
||||
inOrder(root.left);
|
||||
list.add(root.val);
|
||||
inOrder(root.right);
|
||||
@@ -37,7 +37,7 @@ public class binary_tree_dfs {
|
||||
static void postOrder(TreeNode root) {
|
||||
if (root == null)
|
||||
return;
|
||||
// 訪問優先度: 左部分木 -> 右部分木 -> 根ノード
|
||||
// 訪問優先順: 左部分木 -> 右部分木 -> 根ノード
|
||||
postOrder(root.left);
|
||||
postOrder(root.right);
|
||||
list.add(root.val);
|
||||
@@ -45,24 +45,24 @@ public class binary_tree_dfs {
|
||||
|
||||
public static void main(String[] args) {
|
||||
/* 二分木を初期化 */
|
||||
// 特定の関数を使用して配列を二分木に変換
|
||||
// ここでは、配列から直接二分木を生成する関数を利用する
|
||||
TreeNode root = TreeNode.listToTree(Arrays.asList(1, 2, 3, 4, 5, 6, 7));
|
||||
System.out.println("\n二分木を初期化\n");
|
||||
PrintUtil.printTree(root);
|
||||
|
||||
/* 前順走査 */
|
||||
/* 先行順走査 */
|
||||
list.clear();
|
||||
preOrder(root);
|
||||
System.out.println("\n前順走査でのノードの出力順序 = " + list);
|
||||
System.out.println("\n先行順走査のノード出力シーケンス = " + list);
|
||||
|
||||
/* 中順走査 */
|
||||
list.clear();
|
||||
inOrder(root);
|
||||
System.out.println("\n中順走査でのノードの出力順序 = " + list);
|
||||
System.out.println("\n中間順走査のノード出力シーケンス = " + list);
|
||||
|
||||
/* 後順走査 */
|
||||
list.clear();
|
||||
postOrder(root);
|
||||
System.out.println("\n後順走査でのノードの出力順序 = " + list);
|
||||
System.out.println("\n後行順走査のノード出力シーケンス = " + list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user