Merge the chapter of binary tree and searching.

pull/513/head
krahets 2 years ago
parent b5eb9ca271
commit d3cc149c5a

@ -10,7 +10,6 @@ add_subdirectory(chapter_array_and_linkedlist)
add_subdirectory(chapter_stack_and_queue)
add_subdirectory(chapter_heap)
add_subdirectory(chapter_hashing)
add_subdirectory(chapter_binary_search)
add_subdirectory(chapter_tree)
add_subdirectory(chapter_searching)
add_subdirectory(chapter_sorting)

@ -1 +0,0 @@
add_executable(binary_search binary_search.c)

@ -1 +1,2 @@
add_executable(binary_search binary_search.c)
add_executable(two_sum two_sum.c)

@ -8,7 +8,6 @@ include_directories(./include)
add_subdirectory(chapter_computational_complexity)
add_subdirectory(chapter_array_and_linkedlist)
add_subdirectory(chapter_stack_and_queue)
add_subdirectory(chapter_binary_search)
add_subdirectory(chapter_hashing)
add_subdirectory(chapter_tree)
add_subdirectory(chapter_heap)

@ -1 +0,0 @@
add_executable(binary_search binary_search.cpp)

@ -1,3 +1,5 @@
add_executable(binary_search binary_search.cpp)
add_executable(binary_search binary_search_edge.cpp)
add_executable(hashing_search hashing_search.cpp)
add_executable(two_sum two_sum.cpp)
add_executable(linear_search linear_search.cpp)

@ -4,7 +4,7 @@
* Author: haptear (haptear@hotmail.com)
*/
namespace hello_algo.chapter_binary_search;
namespace hello_algo.chapter_searching;
public class binary_search {
/* 二分查找(双闭区间) */

@ -2,7 +2,7 @@
// Created Time: 2022-12-05
// Author: Slone123c (274325721@qq.com)
package chapter_binary_search
package chapter_searching
/* 二分查找(双闭区间) */
func binarySearch(nums []int, target int) int {

@ -2,7 +2,7 @@
// Created Time: 2022-12-05
// Author: Slone123c (274325721@qq.com)
package chapter_binary_search
package chapter_searching
import (
"fmt"
@ -11,14 +11,14 @@ import (
func TestBinarySearch(t *testing.T) {
var (
target = 3
nums = []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
target = 6
nums = []int{1, 3, 6, 8, 12, 15, 23, 67, 70, 92}
expected = 2
)
// 在数组中执行二分查找
actual := binarySearch(nums, target)
fmt.Println("目标元素 3 的索引 =", actual)
fmt.Println("目标元素 6 的索引 =", actual)
if actual != expected {
t.Errorf("目标元素 3 的索引 = %d, 应该为 %d", actual, expected)
t.Errorf("目标元素 6 的索引 = %d, 应该为 %d", actual, expected)
}
}

@ -4,7 +4,7 @@
* Author: Krahets (krahets@163.com)
*/
package chapter_binary_search;
package chapter_searching;
public class binary_search {
/* 二分查找(双闭区间) */

@ -4,7 +4,7 @@
* Author: Krahets (krahets@163.com)
*/
package chapter_binary_search;
package chapter_searching;
public class binary_search_edge {
/* 二分查找最左一个元素 */

@ -24,8 +24,6 @@ let package = Package(
.executable(name: "deque", targets: ["deque"]),
.executable(name: "linkedlist_deque", targets: ["linkedlist_deque"]),
.executable(name: "array_deque", targets: ["array_deque"]),
// chapter_binary_search
.executable(name: "binary_search", targets: ["binary_search"]),
// chapter_hashing
.executable(name: "hash_map", targets: ["hash_map"]),
.executable(name: "array_hash_map", targets: ["array_hash_map"]),
@ -43,6 +41,7 @@ let package = Package(
.executable(name: "graph_bfs", targets: ["graph_bfs"]),
.executable(name: "graph_dfs", targets: ["graph_dfs"]),
// chapter_searching
.executable(name: "binary_search", targets: ["binary_search"]),
.executable(name: "two_sum", targets: ["two_sum"]),
.executable(name: "linear_search", targets: ["linear_search"]),
.executable(name: "hashing_search", targets: ["hashing_search"]),
@ -86,8 +85,6 @@ let package = Package(
.executableTarget(name: "deque", path: "chapter_stack_and_queue", sources: ["deque.swift"]),
.executableTarget(name: "linkedlist_deque", path: "chapter_stack_and_queue", sources: ["linkedlist_deque.swift"]),
.executableTarget(name: "array_deque", path: "chapter_stack_and_queue", sources: ["array_deque.swift"]),
// chapter_binary_search
.executableTarget(name: "binary_search", path: "chapter_binary_search", sources: ["binary_search.swift"]),
// chapter_hashing
.executableTarget(name: "hash_map", dependencies: ["utils"], path: "chapter_hashing", sources: ["hash_map.swift"]),
.executableTarget(name: "array_hash_map", path: "chapter_hashing", sources: ["array_hash_map.swift"]),
@ -105,6 +102,7 @@ let package = Package(
.executableTarget(name: "graph_bfs", dependencies: ["utils", "graph_adjacency_list_target"], path: "chapter_graph", sources: ["graph_bfs.swift"]),
.executableTarget(name: "graph_dfs", dependencies: ["utils", "graph_adjacency_list_target"], path: "chapter_graph", sources: ["graph_dfs.swift"]),
// chapter_searching
.executableTarget(name: "binary_search", path: "chapter_searching", sources: ["binary_search.swift"]),
.executableTarget(name: "two_sum", path: "chapter_searching", sources: ["two_sum.swift"]),
.executableTarget(name: "linear_search", dependencies: ["utils"], path: "chapter_searching", sources: ["linear_search.swift"]),
.executableTarget(name: "hashing_search", dependencies: ["utils"], path: "chapter_searching", sources: ["hashing_search.swift"]),

@ -153,29 +153,32 @@ nav:
- 5.2.   队列: chapter_stack_and_queue/queue.md
- 5.3.   双向队列: chapter_stack_and_queue/deque.md
- 5.4.   小结: chapter_stack_and_queue/summary.md
- 6.     二分查找:
- 6.1.   二分查找: chapter_binary_search/binary_search.md
- 6.2.   二分查找边界: chapter_binary_search/binary_search_edge.md
- 7.     散列表:
- 7.1.   哈希表: chapter_hashing/hash_map.md
- 7.2.   哈希冲突处理: chapter_hashing/hash_collision.md
- 7.3.   小结: chapter_hashing/summary.md
- 8.     树:
- 8.1.   二叉树: chapter_tree/binary_tree.md
- 8.2.   二叉树遍历: chapter_tree/binary_tree_traversal.md
- 8.3.   二叉树数组表示: chapter_tree/array_representation_of_tree.md
- 8.4.   二叉搜索树: chapter_tree/binary_search_tree.md
- 8.5.   AVL 树 *: chapter_tree/avl_tree.md
- 8.6.   小结: chapter_tree/summary.md
- 9.     堆:
- 9.1.   堆: chapter_heap/heap.md
- 9.2.   建堆操作 *: chapter_heap/build_heap.md
- 9.3.   小结: chapter_heap/summary.md
- 10.     图:
- 10.1.   图: chapter_graph/graph.md
- 10.2.   图基础操作: chapter_graph/graph_operations.md
- 10.3.   图的遍历: chapter_graph/graph_traversal.md
- 10.4.   小结: chapter_graph/summary.md
- 6.     散列表:
- 6.1.   哈希表: chapter_hashing/hash_map.md
- 6.2.   哈希冲突处理: chapter_hashing/hash_collision.md
- 6.3.   小结: chapter_hashing/summary.md
- 7.     树:
- 7.1.   二叉树: chapter_tree/binary_tree.md
- 7.2.   二叉树遍历: chapter_tree/binary_tree_traversal.md
- 7.3.   二叉树数组表示: chapter_tree/array_representation_of_tree.md
- 7.4.   二叉搜索树: chapter_tree/binary_search_tree.md
- 7.5.   AVL 树 *: chapter_tree/avl_tree.md
- 7.6.   小结: chapter_tree/summary.md
- 8.     堆:
- 8.1.   堆: chapter_heap/heap.md
- 8.2.   建堆操作 *: chapter_heap/build_heap.md
- 8.3.   小结: chapter_heap/summary.md
- 9.     图:
- 9.1.   图: chapter_graph/graph.md
- 9.2.   图基础操作: chapter_graph/graph_operations.md
- 9.3.   图的遍历: chapter_graph/graph_traversal.md
- 9.4.   小结: chapter_graph/summary.md
- 10.     搜索算法:
- 10.1.   二分查找New: chapter_searching/binary_search.md
- 10.2.   二分查找边界New: chapter_searching/binary_search_edge.md
- 10.3.   哈希优化策略: chapter_searching/replace_linear_by_hashing.md
- 10.4.   重识搜索算法: chapter_searching/searching_algorithm_revisited.md
- 10.5.   小结: chapter_searching/summary.md
- 11.     排序算法:
- 11.1.   排序算法: chapter_sorting/sorting_algorithm.md
- 11.2.   冒泡排序: chapter_sorting/bubble_sort.md
@ -186,16 +189,12 @@ nav:
- 11.7.   计数排序: chapter_sorting/counting_sort.md
- 11.8.   基数排序: chapter_sorting/radix_sort.md
- 11.9.   小结: chapter_sorting/summary.md
- 12.     搜索算法:
- 12.1.   搜索算法New: chapter_searching/searching_algorithm_revisited.md
- 12.2.   哈希优化策略: chapter_searching/replace_linear_by_hashing.md
- 12.3.   小结: chapter_searching/summary.md
- 13.     回溯算法:
- 13.1.   回溯算法New: chapter_backtracking/backtracking_algorithm.md
- 13.2.   全排列问题New: chapter_backtracking/permutations_problem.md
- 13.3.   N 皇后问题New: chapter_backtracking/n_queens_problem.md
- 14.     附录:
- 14.1.   编程环境安装: chapter_appendix/installation.md
- 14.2.   一起参与创作: chapter_appendix/contribution.md
- 12.     回溯算法:
- 12.1.   回溯算法New: chapter_backtracking/backtracking_algorithm.md
- 12.2.   全排列问题New: chapter_backtracking/permutations_problem.md
- 12.3.   N 皇后问题New: chapter_backtracking/n_queens_problem.md
- 13.     附录:
- 13.1.   编程环境安装: chapter_appendix/installation.md
- 13.2.   一起参与创作: chapter_appendix/contribution.md
- 参考文献:
- chapter_reference/index.md

Loading…
Cancel
Save