mirror of
https://github.com/krahets/hello-algo.git
synced 2025-12-16 03:59:18 +08:00
Merge the chapter of binary tree and searching.
This commit is contained in:
@@ -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"]),
|
||||
|
||||
Reference in New Issue
Block a user