diff --git a/codes/cpp/chapter_tree/binary_tree_bfs.cpp b/codes/cpp/chapter_tree/binary_tree_bfs.cpp index c3694eb9c..8b2ba2d2e 100644 --- a/codes/cpp/chapter_tree/binary_tree_bfs.cpp +++ b/codes/cpp/chapter_tree/binary_tree_bfs.cpp @@ -7,7 +7,7 @@ #include "../include/include.hpp" /* 层序遍历 */ -vector hierOrder(TreeNode* root) { +vector levelOrder(TreeNode* root) { // 初始化队列,加入根结点 queue queue; queue.push(root); @@ -35,7 +35,7 @@ int main() { PrintUtil::printTree(root); /* 层序遍历 */ - vector vec = hierOrder(root); + vector vec = levelOrder(root); cout << endl << "层序遍历的结点打印序列 = "; PrintUtil::printVector(vec); diff --git a/codes/csharp/chapter_tree/binary_tree_bfs.cs b/codes/csharp/chapter_tree/binary_tree_bfs.cs index 0cbbf62f5..2edd07eef 100644 --- a/codes/csharp/chapter_tree/binary_tree_bfs.cs +++ b/codes/csharp/chapter_tree/binary_tree_bfs.cs @@ -13,7 +13,7 @@ public class binary_tree_bfs { /* 层序遍历 */ - public List hierOrder(TreeNode root) + public List levelOrder(TreeNode root) { // 初始化队列,加入根结点 Queue queue = new(); @@ -41,7 +41,7 @@ public class binary_tree_bfs Console.WriteLine("\n初始化二叉树\n"); PrintUtil.PrintTree(root); - List list = hierOrder(root); + List list = levelOrder(root); Console.WriteLine("\n层序遍历的结点打印序列 = " + string.Join(",", list.ToArray())); } } diff --git a/codes/go/chapter_tree/binary_tree_bfs.go b/codes/go/chapter_tree/binary_tree_bfs.go index c10f618e0..8ec46fbe7 100644 --- a/codes/go/chapter_tree/binary_tree_bfs.go +++ b/codes/go/chapter_tree/binary_tree_bfs.go @@ -11,7 +11,7 @@ import ( ) /* 层序遍历 */ -func hierOrder(root *TreeNode) []int { +func levelOrder(root *TreeNode) []int { // 初始化队列,加入根结点 queue := list.New() queue.PushBack(root) diff --git a/codes/go/chapter_tree/binary_tree_bfs_test.go b/codes/go/chapter_tree/binary_tree_bfs_test.go index eafd51bcc..7b1bbf1f5 100644 --- a/codes/go/chapter_tree/binary_tree_bfs_test.go +++ b/codes/go/chapter_tree/binary_tree_bfs_test.go @@ -11,7 +11,7 @@ import ( . "github.com/krahets/hello-algo/pkg" ) -func TestHierOrder(t *testing.T) { +func TestLevelOrder(t *testing.T) { /* 初始化二叉树 */ // 这里借助了一个从数组直接生成二叉树的函数 root := ArrToTree([]any{1, 2, 3, 4, 5, 6, 7}) @@ -19,6 +19,6 @@ func TestHierOrder(t *testing.T) { PrintTree(root) // 层序遍历 - nums := hierOrder(root) + nums := levelOrder(root) fmt.Println("\n层序遍历的结点打印序列 =", nums) } diff --git a/codes/java/chapter_tree/binary_tree_bfs.java b/codes/java/chapter_tree/binary_tree_bfs.java index 578ed2b81..246921dc6 100644 --- a/codes/java/chapter_tree/binary_tree_bfs.java +++ b/codes/java/chapter_tree/binary_tree_bfs.java @@ -11,7 +11,7 @@ import java.util.*; public class binary_tree_bfs { /* 层序遍历 */ - static List hierOrder(TreeNode root) { + static List levelOrder(TreeNode root) { // 初始化队列,加入根结点 Queue queue = new LinkedList<>() {{ add(root); }}; // 初始化一个列表,用于保存遍历序列 @@ -35,7 +35,7 @@ public class binary_tree_bfs { PrintUtil.printTree(root); /* 层序遍历 */ - List list = hierOrder(root); + List list = levelOrder(root); System.out.println("\n层序遍历的结点打印序列 = " + list); } } diff --git a/codes/javascript/chapter_tree/binary_tree_bfs.js b/codes/javascript/chapter_tree/binary_tree_bfs.js index 008ace0ad..c400853ea 100644 --- a/codes/javascript/chapter_tree/binary_tree_bfs.js +++ b/codes/javascript/chapter_tree/binary_tree_bfs.js @@ -8,7 +8,7 @@ const { arrToTree } = require("../include/TreeNode"); const { printTree } = require("../include/PrintUtil"); /* 层序遍历 */ -function hierOrder(root) { +function levelOrder(root) { // 初始化队列,加入根结点 let queue = [root]; // 初始化一个列表,用于保存遍历序列 @@ -33,5 +33,5 @@ console.log("\n初始化二叉树\n"); printTree(root); /* 层序遍历 */ -let list = hierOrder(root); +let list = levelOrder(root); console.log("\n层序遍历的结点打印序列 = " + list); diff --git a/codes/python/chapter_tree/binary_tree_bfs.py b/codes/python/chapter_tree/binary_tree_bfs.py index 657fd51da..dff32bd82 100644 --- a/codes/python/chapter_tree/binary_tree_bfs.py +++ b/codes/python/chapter_tree/binary_tree_bfs.py @@ -10,7 +10,7 @@ from include import * """ 层序遍历 """ -def hier_order(root: Optional[TreeNode]): +def level_order(root: Optional[TreeNode]): # 初始化队列,加入根结点 queue = collections.deque() queue.append(root) @@ -35,6 +35,6 @@ if __name__ == "__main__": print_tree(root) # 层序遍历 - res = hier_order(root) + res = level_order(root) print("\n层序遍历的结点打印序列 = ", res) assert res == [1, 2, 3, 4, 5, 6, 7] diff --git a/codes/swift/chapter_tree/binary_tree_bfs.swift b/codes/swift/chapter_tree/binary_tree_bfs.swift index a0aa3cd00..326214a92 100644 --- a/codes/swift/chapter_tree/binary_tree_bfs.swift +++ b/codes/swift/chapter_tree/binary_tree_bfs.swift @@ -7,7 +7,7 @@ import utils /* 层序遍历 */ -func hierOrder(root: TreeNode) -> [Int] { +func levelOrder(root: TreeNode) -> [Int] { // 初始化队列,加入根结点 var queue: [TreeNode] = [root] // 初始化一个列表,用于保存遍历序列 @@ -36,7 +36,7 @@ enum BinaryTreeBFS { PrintUtil.printTree(root: node) /* 层序遍历 */ - let list = hierOrder(root: node) + let list = levelOrder(root: node) print("\n层序遍历的结点打印序列 = \(list)") } } diff --git a/codes/typescript/chapter_tree/binary_tree_bfs.ts b/codes/typescript/chapter_tree/binary_tree_bfs.ts index f723e0486..83fba5c8b 100644 --- a/codes/typescript/chapter_tree/binary_tree_bfs.ts +++ b/codes/typescript/chapter_tree/binary_tree_bfs.ts @@ -9,7 +9,7 @@ import { arrToTree } from '../module/TreeNode'; import { printTree } from '../module/PrintUtil'; /* 层序遍历 */ -function hierOrder(root: TreeNode | null): number[] { +function levelOrder(root: TreeNode | null): number[] { // 初始化队列,加入根结点 const queue = [root]; // 初始化一个列表,用于保存遍历序列 @@ -35,7 +35,7 @@ console.log('\n初始化二叉树\n'); printTree(root); /* 层序遍历 */ -const list = hierOrder(root); +const list = levelOrder(root); console.log('\n层序遍历的结点打印序列 = ' + list); export {}; diff --git a/codes/zig/chapter_tree/binary_tree_bfs.zig b/codes/zig/chapter_tree/binary_tree_bfs.zig index eaa0d0d5a..dc0cb6720 100644 --- a/codes/zig/chapter_tree/binary_tree_bfs.zig +++ b/codes/zig/chapter_tree/binary_tree_bfs.zig @@ -6,7 +6,7 @@ const std = @import("std"); const inc = @import("include"); // 层序遍历 -fn hierOrder(comptime T: type, mem_allocator: std.mem.Allocator, root: *inc.TreeNode(T)) !std.ArrayList(T) { +fn levelOrder(comptime T: type, mem_allocator: std.mem.Allocator, root: *inc.TreeNode(T)) !std.ArrayList(T) { // 初始化队列,加入根结点 const L = std.TailQueue(*inc.TreeNode(T)); var queue = L{}; @@ -48,7 +48,7 @@ pub fn main() !void { try inc.PrintUtil.printTree(root, null, false); // 层序遍历 - var list = try hierOrder(i32, mem_allocator, root.?); + var list = try levelOrder(i32, mem_allocator, root.?); defer list.deinit(); std.debug.print("\n层序遍历的结点打印序列 = ", .{}); inc.PrintUtil.printList(i32, list);