diff --git a/404.html b/404.html index 61fb37463..954ac9c48 100644 --- a/404.html +++ b/404.html @@ -404,7 +404,7 @@ - + 1.   初识算法 @@ -680,7 +680,7 @@ - + 3.   数据结构 @@ -847,7 +847,7 @@ - + 4.   数组与链表 @@ -2245,7 +2245,7 @@ - + 12.   分治 diff --git a/chapter_appendix/contribution/index.html b/chapter_appendix/contribution/index.html index c846ec506..5c66ade22 100644 --- a/chapter_appendix/contribution/index.html +++ b/chapter_appendix/contribution/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2256,7 +2256,7 @@ - + 12.   分治 diff --git a/chapter_appendix/index.html b/chapter_appendix/index.html index b77800b16..eb07e6602 100644 --- a/chapter_appendix/index.html +++ b/chapter_appendix/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2256,7 +2256,7 @@ - + 12.   分治 diff --git a/chapter_appendix/installation/index.html b/chapter_appendix/installation/index.html index c66f3d512..0dcc4f43e 100644 --- a/chapter_appendix/installation/index.html +++ b/chapter_appendix/installation/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2256,7 +2256,7 @@ - + 12.   分治 diff --git a/chapter_array_and_linkedlist/array/index.html b/chapter_array_and_linkedlist/array/index.html index 21f4d987a..d846e0ea4 100644 --- a/chapter_array_and_linkedlist/array/index.html +++ b/chapter_array_and_linkedlist/array/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -860,7 +860,7 @@ - + 4.   数组与链表 @@ -2326,7 +2326,7 @@ - + 12.   分治 @@ -4133,9 +4133,14 @@

4.1.4.   数组典型应用

-

随机访问。如果我们想要随机抽取一些样本,那么可以用数组存储,并生成一个随机序列,根据索引实现样本的随机抽取。

-

二分查找。例如前文查字典的例子,我们可以将字典中的所有字按照拼音顺序存储在数组中,然后使用与日常查纸质字典相同的“翻开中间,排除一半”的方式,来实现一个查电子字典的算法。

-

深度学习。神经网络中大量使用了向量、矩阵、张量之间的线性代数运算,这些数据都是以数组的形式构建的。数组是神经网络编程中最常使用的数据结构。

+

数组是最基础的数据结构,在各类数据结构和算法中都有广泛应用。

+ diff --git a/chapter_array_and_linkedlist/index.html b/chapter_array_and_linkedlist/index.html index 436f5245d..6c2498377 100644 --- a/chapter_array_and_linkedlist/index.html +++ b/chapter_array_and_linkedlist/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -860,7 +860,7 @@ - + 4.   数组与链表 @@ -2258,7 +2258,7 @@ - + 12.   分治 diff --git a/chapter_array_and_linkedlist/linked_list/index.html b/chapter_array_and_linkedlist/linked_list/index.html index 1584343c4..44831f727 100644 --- a/chapter_array_and_linkedlist/linked_list/index.html +++ b/chapter_array_and_linkedlist/linked_list/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -860,7 +860,7 @@ - + 4.   数组与链表 @@ -981,6 +981,13 @@ 4.2.4.   常见链表类型 + + +
  • + + 4.2.5.   链表典型应用 + +
  • @@ -2326,7 +2333,7 @@ - + 12.   分治 @@ -3159,6 +3166,13 @@ 4.2.4.   常见链表类型 + + +
  • + + 4.2.5.   链表典型应用 + +
  • @@ -4224,6 +4238,25 @@

    常见链表种类

    Fig. 常见链表种类

    +

    4.2.5.   链表典型应用

    +

    单向链表通常用于实现栈、队列、散列表和图等数据结构。

    + +

    双向链表常被用于需要快速查找前一个和下一个元素的场景。

    + +

    循环链表常被用于需要周期性操作的场景,比如操作系统的资源调度。

    + + diff --git a/chapter_array_and_linkedlist/list/index.html b/chapter_array_and_linkedlist/list/index.html index 379f1c555..e56efc969 100644 --- a/chapter_array_and_linkedlist/list/index.html +++ b/chapter_array_and_linkedlist/list/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -860,7 +860,7 @@ - + 4.   数组与链表 @@ -2312,7 +2312,7 @@ - + 12.   分治 diff --git a/chapter_array_and_linkedlist/summary/index.html b/chapter_array_and_linkedlist/summary/index.html index ad86e60c5..fb17636b0 100644 --- a/chapter_array_and_linkedlist/summary/index.html +++ b/chapter_array_and_linkedlist/summary/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -860,7 +860,7 @@ - + 4.   数组与链表 @@ -2305,7 +2305,7 @@ - + 12.   分治 diff --git a/chapter_backtracking/backtracking_algorithm/index.html b/chapter_backtracking/backtracking_algorithm/index.html index 9f566ed4e..6da51447b 100644 --- a/chapter_backtracking/backtracking_algorithm/index.html +++ b/chapter_backtracking/backtracking_algorithm/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2256,7 +2256,7 @@ - + 12.   分治 diff --git a/chapter_backtracking/index.html b/chapter_backtracking/index.html index 906beda7d..0866ff12a 100644 --- a/chapter_backtracking/index.html +++ b/chapter_backtracking/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2256,7 +2256,7 @@ - + 12.   分治 diff --git a/chapter_backtracking/n_queens_problem/index.html b/chapter_backtracking/n_queens_problem/index.html index 07c1dcc8f..bcc1bf98c 100644 --- a/chapter_backtracking/n_queens_problem/index.html +++ b/chapter_backtracking/n_queens_problem/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2256,7 +2256,7 @@ - + 12.   分治 diff --git a/chapter_backtracking/permutations_problem/index.html b/chapter_backtracking/permutations_problem/index.html index 20db37c44..bc8cb4a41 100644 --- a/chapter_backtracking/permutations_problem/index.html +++ b/chapter_backtracking/permutations_problem/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2256,7 +2256,7 @@ - + 12.   分治 diff --git a/chapter_backtracking/subset_sum_problem/index.html b/chapter_backtracking/subset_sum_problem/index.html index 3751edc4e..606de45e3 100644 --- a/chapter_backtracking/subset_sum_problem/index.html +++ b/chapter_backtracking/subset_sum_problem/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2256,7 +2256,7 @@ - + 12.   分治 diff --git a/chapter_backtracking/summary/index.html b/chapter_backtracking/summary/index.html index 686489713..7d74bf410 100644 --- a/chapter_backtracking/summary/index.html +++ b/chapter_backtracking/summary/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2256,7 +2256,7 @@ - + 12.   分治 diff --git a/chapter_computational_complexity/index.html b/chapter_computational_complexity/index.html index 28bb9d8e0..3fe9feb4d 100644 --- a/chapter_computational_complexity/index.html +++ b/chapter_computational_complexity/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -693,7 +693,7 @@ - + 3.   数据结构 @@ -860,7 +860,7 @@ - + 4.   数组与链表 @@ -2258,7 +2258,7 @@ - + 12.   分治 diff --git a/chapter_computational_complexity/performance_evaluation/index.html b/chapter_computational_complexity/performance_evaluation/index.html index 3c34f001d..1c72b0624 100644 --- a/chapter_computational_complexity/performance_evaluation/index.html +++ b/chapter_computational_complexity/performance_evaluation/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -774,7 +774,7 @@ - + 3.   数据结构 @@ -941,7 +941,7 @@ - + 4.   数组与链表 @@ -2339,7 +2339,7 @@ - + 12.   分治 diff --git a/chapter_computational_complexity/space_complexity/index.html b/chapter_computational_complexity/space_complexity/index.html index 5951cb8ce..8d7c7eefb 100644 --- a/chapter_computational_complexity/space_complexity/index.html +++ b/chapter_computational_complexity/space_complexity/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -802,7 +802,7 @@ - + 3.   数据结构 @@ -969,7 +969,7 @@ - + 4.   数组与链表 @@ -2367,7 +2367,7 @@ - + 12.   分治 diff --git a/chapter_computational_complexity/summary/index.html b/chapter_computational_complexity/summary/index.html index a262f412e..93c4222e5 100644 --- a/chapter_computational_complexity/summary/index.html +++ b/chapter_computational_complexity/summary/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -740,7 +740,7 @@ - + 3.   数据结构 @@ -907,7 +907,7 @@ - + 4.   数组与链表 @@ -2305,7 +2305,7 @@ - + 12.   分治 diff --git a/chapter_computational_complexity/time_complexity/index.html b/chapter_computational_complexity/time_complexity/index.html index 3003a039e..1735ea4a7 100644 --- a/chapter_computational_complexity/time_complexity/index.html +++ b/chapter_computational_complexity/time_complexity/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -850,7 +850,7 @@ - + 3.   数据结构 @@ -1017,7 +1017,7 @@ - + 4.   数组与链表 @@ -2415,7 +2415,7 @@ - + 12.   分治 diff --git a/chapter_data_structure/basic_data_types/index.html b/chapter_data_structure/basic_data_types/index.html index 74eb6e530..6a4c0a959 100644 --- a/chapter_data_structure/basic_data_types/index.html +++ b/chapter_data_structure/basic_data_types/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -693,7 +693,7 @@ - + 3.   数据结构 @@ -870,7 +870,7 @@ - + 4.   数组与链表 @@ -2268,7 +2268,7 @@ - + 12.   分治 diff --git a/chapter_data_structure/character_encoding/index.html b/chapter_data_structure/character_encoding/index.html index 6156e89a7..3c717c417 100644 --- a/chapter_data_structure/character_encoding/index.html +++ b/chapter_data_structure/character_encoding/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -693,7 +693,7 @@ - + 3.   数据结构 @@ -935,7 +935,7 @@ - + 4.   数组与链表 @@ -2333,7 +2333,7 @@ - + 12.   分治 diff --git a/chapter_data_structure/classification_of_data_structure/index.html b/chapter_data_structure/classification_of_data_structure/index.html index c06dddf51..be4988573 100644 --- a/chapter_data_structure/classification_of_data_structure/index.html +++ b/chapter_data_structure/classification_of_data_structure/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -693,7 +693,7 @@ - + 3.   数据结构 @@ -914,7 +914,7 @@ - + 4.   数组与链表 @@ -2312,7 +2312,7 @@ - + 12.   分治 diff --git a/chapter_data_structure/index.html b/chapter_data_structure/index.html index de647fc8f..1bb197eeb 100644 --- a/chapter_data_structure/index.html +++ b/chapter_data_structure/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -693,7 +693,7 @@ - + 3.   数据结构 @@ -860,7 +860,7 @@ - + 4.   数组与链表 @@ -2258,7 +2258,7 @@ - + 12.   分治 diff --git a/chapter_data_structure/number_encoding/index.html b/chapter_data_structure/number_encoding/index.html index 4c4f23a5f..9d7567482 100644 --- a/chapter_data_structure/number_encoding/index.html +++ b/chapter_data_structure/number_encoding/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -693,7 +693,7 @@ - + 3.   数据结构 @@ -914,7 +914,7 @@ - + 4.   数组与链表 @@ -2312,7 +2312,7 @@ - + 12.   分治 diff --git a/chapter_data_structure/summary/index.html b/chapter_data_structure/summary/index.html index 8a83a8e2d..a959932b5 100644 --- a/chapter_data_structure/summary/index.html +++ b/chapter_data_structure/summary/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -693,7 +693,7 @@ - + 3.   数据结构 @@ -907,7 +907,7 @@ - + 4.   数组与链表 @@ -2305,7 +2305,7 @@ - + 12.   分治 diff --git a/chapter_divide_and_conquer/binary_search_recur/index.html b/chapter_divide_and_conquer/binary_search_recur/index.html index 340a24e73..8c8f7ecb9 100644 --- a/chapter_divide_and_conquer/binary_search_recur/index.html +++ b/chapter_divide_and_conquer/binary_search_recur/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2258,7 +2258,7 @@ - + 12.   分治 diff --git a/chapter_divide_and_conquer/build_binary_tree_problem/index.html b/chapter_divide_and_conquer/build_binary_tree_problem/index.html index c29abde1c..9b03027bb 100644 --- a/chapter_divide_and_conquer/build_binary_tree_problem/index.html +++ b/chapter_divide_and_conquer/build_binary_tree_problem/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2258,7 +2258,7 @@ - + 12.   分治 diff --git a/chapter_divide_and_conquer/divide_and_conquer/index.html b/chapter_divide_and_conquer/divide_and_conquer/index.html index e82e466c8..bd2de4528 100644 --- a/chapter_divide_and_conquer/divide_and_conquer/index.html +++ b/chapter_divide_and_conquer/divide_and_conquer/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2258,7 +2258,7 @@ - + 12.   分治 diff --git a/chapter_divide_and_conquer/hanota_problem/index.html b/chapter_divide_and_conquer/hanota_problem/index.html index c1a6f1a18..ac1369a9d 100644 --- a/chapter_divide_and_conquer/hanota_problem/index.html +++ b/chapter_divide_and_conquer/hanota_problem/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2258,7 +2258,7 @@ - + 12.   分治 diff --git a/chapter_divide_and_conquer/index.html b/chapter_divide_and_conquer/index.html index f83ed273c..55d56d5d9 100644 --- a/chapter_divide_and_conquer/index.html +++ b/chapter_divide_and_conquer/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2258,7 +2258,7 @@ - + 12.   分治 diff --git a/chapter_divide_and_conquer/summary/index.html b/chapter_divide_and_conquer/summary/index.html index dcc998c51..3fc80caac 100644 --- a/chapter_divide_and_conquer/summary/index.html +++ b/chapter_divide_and_conquer/summary/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2258,7 +2258,7 @@ - + 12.   分治 diff --git a/chapter_dynamic_programming/dp_problem_features/index.html b/chapter_dynamic_programming/dp_problem_features/index.html index 81f926992..949139d29 100644 --- a/chapter_dynamic_programming/dp_problem_features/index.html +++ b/chapter_dynamic_programming/dp_problem_features/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2256,7 +2256,7 @@ - + 12.   分治 diff --git a/chapter_dynamic_programming/dp_solution_pipeline/index.html b/chapter_dynamic_programming/dp_solution_pipeline/index.html index dc49544b4..25c75766c 100644 --- a/chapter_dynamic_programming/dp_solution_pipeline/index.html +++ b/chapter_dynamic_programming/dp_solution_pipeline/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2256,7 +2256,7 @@ - + 12.   分治 diff --git a/chapter_dynamic_programming/edit_distance_problem/index.html b/chapter_dynamic_programming/edit_distance_problem/index.html index 97bf69ea8..e5c9b5b18 100644 --- a/chapter_dynamic_programming/edit_distance_problem/index.html +++ b/chapter_dynamic_programming/edit_distance_problem/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2256,7 +2256,7 @@ - + 12.   分治 diff --git a/chapter_dynamic_programming/index.html b/chapter_dynamic_programming/index.html index 409292f0b..4aa3acf12 100644 --- a/chapter_dynamic_programming/index.html +++ b/chapter_dynamic_programming/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2256,7 +2256,7 @@ - + 12.   分治 diff --git a/chapter_dynamic_programming/intro_to_dynamic_programming/index.html b/chapter_dynamic_programming/intro_to_dynamic_programming/index.html index 7d73f1293..2c71b33f7 100644 --- a/chapter_dynamic_programming/intro_to_dynamic_programming/index.html +++ b/chapter_dynamic_programming/intro_to_dynamic_programming/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2256,7 +2256,7 @@ - + 12.   分治 diff --git a/chapter_dynamic_programming/knapsack_problem/index.html b/chapter_dynamic_programming/knapsack_problem/index.html index 088c8d31b..a806e0dd4 100644 --- a/chapter_dynamic_programming/knapsack_problem/index.html +++ b/chapter_dynamic_programming/knapsack_problem/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2256,7 +2256,7 @@ - + 12.   分治 diff --git a/chapter_dynamic_programming/summary/index.html b/chapter_dynamic_programming/summary/index.html index 90ed7df80..6c4f67e6c 100644 --- a/chapter_dynamic_programming/summary/index.html +++ b/chapter_dynamic_programming/summary/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2256,7 +2256,7 @@ - + 12.   分治 diff --git a/chapter_dynamic_programming/unbounded_knapsack_problem/index.html b/chapter_dynamic_programming/unbounded_knapsack_problem/index.html index 17dd4ada2..0f81c47e2 100644 --- a/chapter_dynamic_programming/unbounded_knapsack_problem/index.html +++ b/chapter_dynamic_programming/unbounded_knapsack_problem/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2256,7 +2256,7 @@ - + 12.   分治 diff --git a/chapter_graph/graph/index.html b/chapter_graph/graph/index.html index 2a789d1ab..58e99841e 100644 --- a/chapter_graph/graph/index.html +++ b/chapter_graph/graph/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2346,7 +2346,7 @@ - + 12.   分治 diff --git a/chapter_graph/graph_operations/index.html b/chapter_graph/graph_operations/index.html index d4deacf18..931d2560e 100644 --- a/chapter_graph/graph_operations/index.html +++ b/chapter_graph/graph_operations/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2319,7 +2319,7 @@ - + 12.   分治 diff --git a/chapter_graph/graph_traversal/index.html b/chapter_graph/graph_traversal/index.html index b809e1acf..709afae54 100644 --- a/chapter_graph/graph_traversal/index.html +++ b/chapter_graph/graph_traversal/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2352,7 +2352,7 @@ - + 12.   分治 diff --git a/chapter_graph/index.html b/chapter_graph/index.html index 0d6b07649..f078a23fe 100644 --- a/chapter_graph/index.html +++ b/chapter_graph/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2258,7 +2258,7 @@ - + 12.   分治 diff --git a/chapter_graph/summary/index.html b/chapter_graph/summary/index.html index 4adde8400..9ca96e655 100644 --- a/chapter_graph/summary/index.html +++ b/chapter_graph/summary/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2305,7 +2305,7 @@ - + 12.   分治 diff --git a/chapter_hashing/hash_algorithm/index.html b/chapter_hashing/hash_algorithm/index.html index 48ce77644..b63fef9d7 100644 --- a/chapter_hashing/hash_algorithm/index.html +++ b/chapter_hashing/hash_algorithm/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2326,7 +2326,7 @@ - + 12.   分治 diff --git a/chapter_hashing/hash_collision/index.html b/chapter_hashing/hash_collision/index.html index 39e62e7df..0a5d1bb63 100644 --- a/chapter_hashing/hash_collision/index.html +++ b/chapter_hashing/hash_collision/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2332,7 +2332,7 @@ - + 12.   分治 diff --git a/chapter_hashing/hash_map/index.html b/chapter_hashing/hash_map/index.html index 1e1984a42..84d27927d 100644 --- a/chapter_hashing/hash_map/index.html +++ b/chapter_hashing/hash_map/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2319,7 +2319,7 @@ - + 12.   分治 diff --git a/chapter_hashing/index.html b/chapter_hashing/index.html index 4abd838d3..c7efdc3b8 100644 --- a/chapter_hashing/index.html +++ b/chapter_hashing/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2258,7 +2258,7 @@ - + 12.   分治 diff --git a/chapter_hashing/summary/index.html b/chapter_hashing/summary/index.html index 1a851a219..1bfbec245 100644 --- a/chapter_hashing/summary/index.html +++ b/chapter_hashing/summary/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2305,7 +2305,7 @@ - + 12.   分治 diff --git a/chapter_heap/build_heap/index.html b/chapter_heap/build_heap/index.html index 3cbb44121..7204baac0 100644 --- a/chapter_heap/build_heap/index.html +++ b/chapter_heap/build_heap/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2319,7 +2319,7 @@ - + 12.   分治 diff --git a/chapter_heap/heap/index.html b/chapter_heap/heap/index.html index 422edbf95..1729a9eef 100644 --- a/chapter_heap/heap/index.html +++ b/chapter_heap/heap/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2353,7 +2353,7 @@ - + 12.   分治 diff --git a/chapter_heap/index.html b/chapter_heap/index.html index 17c86fa4c..c1d99e254 100644 --- a/chapter_heap/index.html +++ b/chapter_heap/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2258,7 +2258,7 @@ - + 12.   分治 diff --git a/chapter_heap/summary/index.html b/chapter_heap/summary/index.html index dcb1a8072..fbd472b22 100644 --- a/chapter_heap/summary/index.html +++ b/chapter_heap/summary/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2305,7 +2305,7 @@ - + 12.   分治 diff --git a/chapter_heap/top_k/index.html b/chapter_heap/top_k/index.html index 7b1aa6983..27b3beb28 100644 --- a/chapter_heap/top_k/index.html +++ b/chapter_heap/top_k/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2319,7 +2319,7 @@ - + 12.   分治 diff --git a/chapter_introduction/algorithms_are_everywhere/index.html b/chapter_introduction/algorithms_are_everywhere/index.html index e9ed3692c..1c65eda18 100644 --- a/chapter_introduction/algorithms_are_everywhere/index.html +++ b/chapter_introduction/algorithms_are_everywhere/index.html @@ -417,7 +417,7 @@ - + 1.   初识算法 @@ -703,7 +703,7 @@ - + 3.   数据结构 @@ -870,7 +870,7 @@ - + 4.   数组与链表 @@ -2268,7 +2268,7 @@ - + 12.   分治 diff --git a/chapter_introduction/index.html b/chapter_introduction/index.html index cbd57909e..3571e6d1b 100644 --- a/chapter_introduction/index.html +++ b/chapter_introduction/index.html @@ -417,7 +417,7 @@ - + 1.   初识算法 @@ -693,7 +693,7 @@ - + 3.   数据结构 @@ -860,7 +860,7 @@ - + 4.   数组与链表 @@ -2258,7 +2258,7 @@ - + 12.   分治 diff --git a/chapter_introduction/summary/index.html b/chapter_introduction/summary/index.html index 7941fe29d..319119194 100644 --- a/chapter_introduction/summary/index.html +++ b/chapter_introduction/summary/index.html @@ -417,7 +417,7 @@ - + 1.   初识算法 @@ -703,7 +703,7 @@ - + 3.   数据结构 @@ -870,7 +870,7 @@ - + 4.   数组与链表 @@ -2268,7 +2268,7 @@ - + 12.   分治 diff --git a/chapter_introduction/what_is_dsa/index.html b/chapter_introduction/what_is_dsa/index.html index f8585a1d9..409ce12ff 100644 --- a/chapter_introduction/what_is_dsa/index.html +++ b/chapter_introduction/what_is_dsa/index.html @@ -417,7 +417,7 @@ - + 1.   初识算法 @@ -754,7 +754,7 @@ - + 3.   数据结构 @@ -921,7 +921,7 @@ - + 4.   数组与链表 @@ -2319,7 +2319,7 @@ - + 12.   分治 diff --git a/chapter_preface/about_the_book/index.html b/chapter_preface/about_the_book/index.html index 3d7bed876..1f4492b15 100644 --- a/chapter_preface/about_the_book/index.html +++ b/chapter_preface/about_the_book/index.html @@ -478,7 +478,7 @@ - + 1.   初识算法 @@ -754,7 +754,7 @@ - + 3.   数据结构 @@ -921,7 +921,7 @@ - + 4.   数组与链表 @@ -2319,7 +2319,7 @@ - + 12.   分治 diff --git a/chapter_preface/index.html b/chapter_preface/index.html index 846f3a5d9..39c3b8899 100644 --- a/chapter_preface/index.html +++ b/chapter_preface/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2256,7 +2256,7 @@ - + 12.   分治 diff --git a/chapter_preface/suggestions/index.html b/chapter_preface/suggestions/index.html index 0be5151a3..1f507ea62 100644 --- a/chapter_preface/suggestions/index.html +++ b/chapter_preface/suggestions/index.html @@ -492,7 +492,7 @@ - + 1.   初识算法 @@ -768,7 +768,7 @@ - + 3.   数据结构 @@ -935,7 +935,7 @@ - + 4.   数组与链表 @@ -2333,7 +2333,7 @@ - + 12.   分治 diff --git a/chapter_preface/summary/index.html b/chapter_preface/summary/index.html index fd736e574..c36e7ef73 100644 --- a/chapter_preface/summary/index.html +++ b/chapter_preface/summary/index.html @@ -427,7 +427,7 @@ - + 1.   初识算法 @@ -703,7 +703,7 @@ - + 3.   数据结构 @@ -870,7 +870,7 @@ - + 4.   数组与链表 @@ -2268,7 +2268,7 @@ - + 12.   分治 diff --git a/chapter_reference/index.html b/chapter_reference/index.html index 42f3b78ae..b4a3c27f3 100644 --- a/chapter_reference/index.html +++ b/chapter_reference/index.html @@ -413,7 +413,7 @@ - + 1.   初识算法 @@ -689,7 +689,7 @@ - + 3.   数据结构 @@ -856,7 +856,7 @@ - + 4.   数组与链表 @@ -2254,7 +2254,7 @@ - + 12.   分治 diff --git a/chapter_searching/binary_search/index.html b/chapter_searching/binary_search/index.html index 54a151da0..ef13b84f8 100644 --- a/chapter_searching/binary_search/index.html +++ b/chapter_searching/binary_search/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2312,7 +2312,7 @@ - + 12.   分治 diff --git a/chapter_searching/binary_search_edge/index.html b/chapter_searching/binary_search_edge/index.html index 7cf060a1f..07fcc8e5e 100644 --- a/chapter_searching/binary_search_edge/index.html +++ b/chapter_searching/binary_search_edge/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2319,7 +2319,7 @@ - + 12.   分治 diff --git a/chapter_searching/index.html b/chapter_searching/index.html index 7c7de9bcf..aca029eef 100644 --- a/chapter_searching/index.html +++ b/chapter_searching/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2258,7 +2258,7 @@ - + 12.   分治 diff --git a/chapter_searching/replace_linear_by_hashing/index.html b/chapter_searching/replace_linear_by_hashing/index.html index 4c99a901f..0216c8e21 100644 --- a/chapter_searching/replace_linear_by_hashing/index.html +++ b/chapter_searching/replace_linear_by_hashing/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2312,7 +2312,7 @@ - + 12.   分治 diff --git a/chapter_searching/searching_algorithm_revisited/index.html b/chapter_searching/searching_algorithm_revisited/index.html index cd7200088..6e0acf23d 100644 --- a/chapter_searching/searching_algorithm_revisited/index.html +++ b/chapter_searching/searching_algorithm_revisited/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2319,7 +2319,7 @@ - + 12.   分治 diff --git a/chapter_searching/summary/index.html b/chapter_searching/summary/index.html index d90073ae7..7c6d81e9b 100644 --- a/chapter_searching/summary/index.html +++ b/chapter_searching/summary/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2268,7 +2268,7 @@ - + 12.   分治 diff --git a/chapter_sorting/bubble_sort/index.html b/chapter_sorting/bubble_sort/index.html index 46faa6c29..c380fffeb 100644 --- a/chapter_sorting/bubble_sort/index.html +++ b/chapter_sorting/bubble_sort/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2319,7 +2319,7 @@ - + 12.   分治 diff --git a/chapter_sorting/bucket_sort/index.html b/chapter_sorting/bucket_sort/index.html index 49a7b7b13..a1a46a8c3 100644 --- a/chapter_sorting/bucket_sort/index.html +++ b/chapter_sorting/bucket_sort/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2319,7 +2319,7 @@ - + 12.   分治 diff --git a/chapter_sorting/counting_sort/index.html b/chapter_sorting/counting_sort/index.html index 14e1cc12c..33b14b472 100644 --- a/chapter_sorting/counting_sort/index.html +++ b/chapter_sorting/counting_sort/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2326,7 +2326,7 @@ - + 12.   分治 diff --git a/chapter_sorting/heap_sort/index.html b/chapter_sorting/heap_sort/index.html index 2686d9f63..114c91ee5 100644 --- a/chapter_sorting/heap_sort/index.html +++ b/chapter_sorting/heap_sort/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2312,7 +2312,7 @@ - + 12.   分治 diff --git a/chapter_sorting/index.html b/chapter_sorting/index.html index 1a7dd5474..96a391313 100644 --- a/chapter_sorting/index.html +++ b/chapter_sorting/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2258,7 +2258,7 @@ - + 12.   分治 diff --git a/chapter_sorting/insertion_sort/index.html b/chapter_sorting/insertion_sort/index.html index ea70fc967..4a29b0d39 100644 --- a/chapter_sorting/insertion_sort/index.html +++ b/chapter_sorting/insertion_sort/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2319,7 +2319,7 @@ - + 12.   分治 diff --git a/chapter_sorting/merge_sort/index.html b/chapter_sorting/merge_sort/index.html index 165fda1a4..eab365a5d 100644 --- a/chapter_sorting/merge_sort/index.html +++ b/chapter_sorting/merge_sort/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2319,7 +2319,7 @@ - + 12.   分治 diff --git a/chapter_sorting/quick_sort/index.html b/chapter_sorting/quick_sort/index.html index 7779987e8..2935a5eb2 100644 --- a/chapter_sorting/quick_sort/index.html +++ b/chapter_sorting/quick_sort/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2333,7 +2333,7 @@ - + 12.   分治 diff --git a/chapter_sorting/radix_sort/index.html b/chapter_sorting/radix_sort/index.html index 8d4f6c5af..e42546f35 100644 --- a/chapter_sorting/radix_sort/index.html +++ b/chapter_sorting/radix_sort/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2312,7 +2312,7 @@ - + 12.   分治 diff --git a/chapter_sorting/selection_sort/index.html b/chapter_sorting/selection_sort/index.html index c6767f512..c136e9418 100644 --- a/chapter_sorting/selection_sort/index.html +++ b/chapter_sorting/selection_sort/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2305,7 +2305,7 @@ - + 12.   分治 diff --git a/chapter_sorting/sorting_algorithm/index.html b/chapter_sorting/sorting_algorithm/index.html index 92c1ad136..1c6348b2a 100644 --- a/chapter_sorting/sorting_algorithm/index.html +++ b/chapter_sorting/sorting_algorithm/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2312,7 +2312,7 @@ - + 12.   分治 diff --git a/chapter_sorting/summary/index.html b/chapter_sorting/summary/index.html index 92e9899bc..fbd8d1cf0 100644 --- a/chapter_sorting/summary/index.html +++ b/chapter_sorting/summary/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2305,7 +2305,7 @@ - + 12.   分治 diff --git a/chapter_stack_and_queue/deque/index.html b/chapter_stack_and_queue/deque/index.html index 50da6ab47..f8df9aecb 100644 --- a/chapter_stack_and_queue/deque/index.html +++ b/chapter_stack_and_queue/deque/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2339,7 +2339,7 @@ - + 12.   分治 diff --git a/chapter_stack_and_queue/index.html b/chapter_stack_and_queue/index.html index 9eb13583d..c9a514fe8 100644 --- a/chapter_stack_and_queue/index.html +++ b/chapter_stack_and_queue/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2258,7 +2258,7 @@ - + 12.   分治 diff --git a/chapter_stack_and_queue/queue/index.html b/chapter_stack_and_queue/queue/index.html index f91dd76ef..de3051c7f 100644 --- a/chapter_stack_and_queue/queue/index.html +++ b/chapter_stack_and_queue/queue/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2339,7 +2339,7 @@ - + 12.   分治 diff --git a/chapter_stack_and_queue/stack/index.html b/chapter_stack_and_queue/stack/index.html index b6c8e5426..1f7292fe5 100644 --- a/chapter_stack_and_queue/stack/index.html +++ b/chapter_stack_and_queue/stack/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2373,7 +2373,7 @@ - + 12.   分治 diff --git a/chapter_stack_and_queue/summary/index.html b/chapter_stack_and_queue/summary/index.html index 4ed10b7df..0c8fb0e5e 100644 --- a/chapter_stack_and_queue/summary/index.html +++ b/chapter_stack_and_queue/summary/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2305,7 +2305,7 @@ - + 12.   分治 diff --git a/chapter_tree/array_representation_of_tree/index.html b/chapter_tree/array_representation_of_tree/index.html index 24ddae1cc..8f839d377 100644 --- a/chapter_tree/array_representation_of_tree/index.html +++ b/chapter_tree/array_representation_of_tree/index.html @@ -415,7 +415,7 @@ - + 1.   初识算法 @@ -691,7 +691,7 @@ - + 3.   数据结构 @@ -858,7 +858,7 @@ - + 4.   数组与链表 @@ -2319,7 +2319,7 @@ - + 12.   分治 @@ -3196,7 +3196,7 @@
    /* 二叉树的数组表示 */
    -// 使用 int 最大值标记空位,因此要求节点值不能为 INT_MAX
    +// 使用 int 最大值 INT_MAX 标记空位
     vector<int> tree = {1, 2, 3, 4, INT_MAX, 6, 7, 8, 9, INT_MAX, INT_MAX, 12, INT_MAX, INT_MAX, 15};
     
    @@ -3257,6 +3257,304 @@

    任意类型二叉树的数组表示

    Fig. 任意类型二叉树的数组表示

    +

    以下为数组表示下二叉树的实现,包括:

    + +
    +
    +
    +
    array_binary_tree.java
    /* 数组表示下的二叉树类 */
    +class ArrayBinaryTree {
    +    private List<Integer> tree;
    +
    +    /* 构造方法 */
    +    public ArrayBinaryTree(List<Integer> arr) {
    +        tree = new ArrayList<>(arr);
    +    }
    +
    +    /* 节点数量 */
    +    public int size() {
    +        return tree.size();
    +    }
    +
    +    /* 获取索引为 i 节点的值 */
    +    public Integer val(int i) {
    +        // 若索引越界,则返回 null ,代表空位
    +        if (i < 0 || i >= size())
    +            return null;
    +        return tree.get(i);
    +    }
    +
    +    /* 获取索引为 i 节点的左子节点的索引 */
    +    public Integer left(int i) {
    +        return 2 * i + 1;
    +    }
    +
    +    /* 获取索引为 i 节点的右子节点的索引 */
    +    public Integer right(int i) {
    +        return 2 * i + 2;
    +    }
    +
    +    /* 获取索引为 i 节点的父节点的索引 */
    +    public Integer parent(int i) {
    +        return (i - 1) / 2;
    +    }
    +
    +    /* 层序遍历 */
    +    public List<Integer> levelOrder() {
    +        List<Integer> res = new ArrayList<>();
    +        // 直接遍历数组
    +        for (int i = 0; i < size(); i++) {
    +            if (val(i) != null)
    +                res.add(val(i));
    +        }
    +        return res;
    +    }
    +
    +    /* 深度优先遍历 */
    +    private void dfs(Integer i, String order, List<Integer> res) {
    +        // 若为空位,则返回
    +        if (val(i) == null)
    +            return;
    +        // 前序遍历
    +        if (order == "pre")
    +            res.add(val(i));
    +        dfs(left(i), order, res);
    +        // 中序遍历
    +        if (order == "in")
    +            res.add(val(i));
    +        dfs(right(i), order, res);
    +        // 后序遍历
    +        if (order == "post")
    +            res.add(val(i));
    +    }
    +
    +    /* 前序遍历 */
    +    public List<Integer> preOrder() {
    +        List<Integer> res = new ArrayList<>();
    +        dfs(0, "pre", res);
    +        return res;
    +    }
    +
    +    /* 中序遍历 */
    +    public List<Integer> inOrder() {
    +        List<Integer> res = new ArrayList<>();
    +        dfs(0, "in", res);
    +        return res;
    +    }
    +
    +    /* 后序遍历 */
    +    public List<Integer> postOrder() {
    +        List<Integer> res = new ArrayList<>();
    +        dfs(0, "post", res);
    +        return res;
    +    }
    +}
    +
    +
    +
    +
    array_binary_tree.cpp
    /* 数组表示下的二叉树类 */
    +class ArrayBinaryTree {
    +  public:
    +    /* 构造方法 */
    +    ArrayBinaryTree(vector<int> arr) {
    +        tree = arr;
    +    }
    +
    +    /* 节点数量 */
    +    int size() {
    +        return tree.size();
    +    }
    +
    +    /* 获取索引为 i 节点的值 */
    +    int val(int i) {
    +        // 若索引越界,则返回 INT_MAX ,代表空位
    +        if (i < 0 || i >= size())
    +            return INT_MAX;
    +        return tree[i];
    +    }
    +
    +    /* 获取索引为 i 节点的左子节点的索引 */
    +    int left(int i) {
    +        return 2 * i + 1;
    +    }
    +
    +    /* 获取索引为 i 节点的右子节点的索引 */
    +    int right(int i) {
    +        return 2 * i + 2;
    +    }
    +
    +    /* 获取索引为 i 节点的父节点的索引 */
    +    int parent(int i) {
    +        return (i - 1) / 2;
    +    }
    +
    +    /* 层序遍历 */
    +    vector<int> levelOrder() {
    +        vector<int> res;
    +        // 直接遍历数组
    +        for (int i = 0; i < size(); i++) {
    +            if (val(i) != INT_MAX)
    +                res.push_back(val(i));
    +        }
    +        return res;
    +    }
    +
    +    /* 前序遍历 */
    +    vector<int> preOrder() {
    +        vector<int> res;
    +        dfs(0, "pre", res);
    +        return res;
    +    }
    +
    +    /* 中序遍历 */
    +    vector<int> inOrder() {
    +        vector<int> res;
    +        dfs(0, "in", res);
    +        return res;
    +    }
    +
    +    /* 后序遍历 */
    +    vector<int> postOrder() {
    +        vector<int> res;
    +        dfs(0, "post", res);
    +        return res;
    +    }
    +
    +  private:
    +    vector<int> tree;
    +
    +    /* 深度优先遍历 */
    +    void dfs(int i, string order, vector<int> &res) {
    +        // 若为空位,则返回
    +        if (val(i) == INT_MAX)
    +            return;
    +        // 前序遍历
    +        if (order == "pre")
    +            res.push_back(val(i));
    +        dfs(left(i), order, res);
    +        // 中序遍历
    +        if (order == "in")
    +            res.push_back(val(i));
    +        dfs(right(i), order, res);
    +        // 后序遍历
    +        if (order == "post")
    +            res.push_back(val(i));
    +    }
    +};
    +
    +
    +
    +
    array_binary_tree.py
    class ArrayBinaryTree:
    +    """数组表示下的二叉树类"""
    +
    +    def __init__(self, arr: list[int | None]):
    +        """构造方法"""
    +        self.__tree = list(arr)
    +
    +    def size(self):
    +        """节点数量"""
    +        return len(self.__tree)
    +
    +    def val(self, i: int) -> int:
    +        """获取索引为 i 节点的值"""
    +        # 若索引越界,则返回 None ,代表空位
    +        if i < 0 or i >= self.size():
    +            return None
    +        return self.__tree[i]
    +
    +    def left(self, i: int) -> int | None:
    +        """获取索引为 i 节点的左子节点的索引"""
    +        return 2 * i + 1
    +
    +    def right(self, i: int) -> int | None:
    +        """获取索引为 i 节点的右子节点的索引"""
    +        return 2 * i + 2
    +
    +    def parent(self, i: int) -> int | None:
    +        """获取索引为 i 节点的父节点的索引"""
    +        return (i - 1) // 2
    +
    +    def level_order(self) -> list[int]:
    +        """层序遍历"""
    +        self.res = []
    +        # 直接遍历数组
    +        for i in range(self.size()):
    +            if self.val(i) is not None:
    +                self.res.append(self.val(i))
    +        return self.res
    +
    +    def __dfs(self, i: int, order: str):
    +        """深度优先遍历"""
    +        if self.val(i) is None:
    +            return
    +        # 前序遍历
    +        if order == "pre":
    +            self.res.append(self.val(i))
    +        self.__dfs(self.left(i), order)
    +        # 中序遍历
    +        if order == "in":
    +            self.res.append(self.val(i))
    +        self.__dfs(self.right(i), order)
    +        # 后序遍历
    +        if order == "post":
    +            self.res.append(self.val(i))
    +
    +    def pre_order(self) -> list[int]:
    +        """前序遍历"""
    +        self.res = []
    +        self.__dfs(0, order="pre")
    +        return self.res
    +
    +    def in_order(self) -> list[int]:
    +        """中序遍历"""
    +        self.res = []
    +        self.__dfs(0, order="in")
    +        return self.res
    +
    +    def post_order(self) -> list[int]:
    +        """后序遍历"""
    +        self.res = []
    +        self.__dfs(0, order="post")
    +        return self.res
    +
    +
    +
    +
    array_binary_tree.go
    [class]{arrayBinaryTree}-[func]{}
    +
    +
    +
    +
    array_binary_tree.js
    [class]{ArrayBinaryTree}-[func]{}
    +
    +
    +
    +
    array_binary_tree.ts
    [class]{ArrayBinaryTree}-[func]{}
    +
    +
    +
    +
    array_binary_tree.c
    [class]{arrayBinaryTree}-[func]{}
    +
    +
    +
    +
    array_binary_tree.cs
    [class]{ArrayBinaryTree}-[func]{}
    +
    +
    +
    +
    array_binary_tree.swift
    [class]{ArrayBinaryTree}-[func]{}
    +
    +
    +
    +
    array_binary_tree.zig
    [class]{ArrayBinaryTree}-[func]{}
    +
    +
    +
    +
    array_binary_tree.dart
    [class]{ArrayBinaryTree}-[func]{}
    +
    +
    +
    +

    7.3.3.   优势与局限性

    二叉树的数组表示存在以下优点: