diff --git a/docs/algorithm.md b/docs/algorithm.md index bd34114..67731c2 100644 --- a/docs/algorithm.md +++ b/docs/algorithm.md @@ -148,7 +148,7 @@ func main() { fmt.Println(peoples) // Output: - //[{d 8} {b 10} {c 17} {a 20} {e 28}] + // [{d 8} {b 10} {c 17} {a 20} {e 28}] } ``` @@ -196,7 +196,7 @@ func main() { fmt.Println(numbers) // Output: - // [1 2 3 4 5 6] + // [1 2 3 4 5 6] } ``` diff --git a/docs/algorithm_zh-CN.md b/docs/algorithm_zh-CN.md index 3ab5ec6..a270c16 100644 --- a/docs/algorithm_zh-CN.md +++ b/docs/algorithm_zh-CN.md @@ -1,17 +1,19 @@ # Algorithm -algorithm算法包实现一些基本算法,sort,search,lrucache。 + +algorithm 算法包实现一些基本算法,sort,search,lrucache。
## 源码 -- [https://github.com/duke-git/lancet/blob/main/algorithm/sort.go](https://github.com/duke-git/lancet/blob/main/algorithm/sort.go) -- [https://github.com/duke-git/lancet/blob/main/algorithm/search.go](https://github.com/duke-git/lancet/blob/main/algorithm/search.go) -- [https://github.com/duke-git/lancet/blob/main/algorithm/lru_cache.go](https://github.com/duke-git/lancet/blob/main/algorithm/lru_cache.go) +- [https://github.com/duke-git/lancet/blob/main/algorithm/sort.go](https://github.com/duke-git/lancet/blob/main/algorithm/sort.go) +- [https://github.com/duke-git/lancet/blob/main/algorithm/search.go](https://github.com/duke-git/lancet/blob/main/algorithm/search.go) +- [https://github.com/duke-git/lancet/blob/main/algorithm/lru_cache.go](https://github.com/duke-git/lancet/blob/main/algorithm/lru_cache.go)
## 用法 + ```go import ( "github.com/duke-git/lancet/v2/algorithm" @@ -22,25 +24,25 @@ import ( ## 目录 -- [BubbleSort](#BubbleSort) -- [InsertionSort](#InsertionSort) -- [SelectionSort](#SelectionSort) -- [ShellSort](#ShellSort) -- [QuickSort](#QuickSort) -- [HeapSort](#HeapSort) -- [MergeSort](#MergeSort) -- [CountSort](#CountSort) -- [BinarySearch](#BinarySearch) -- [BinaryIterativeSearch](#BinaryIterativeSearch) -- [LinearSearch](#LinearSearch) -- [LRUCache](#LRUCache) - +- [BubbleSort](#BubbleSort) +- [InsertionSort](#InsertionSort) +- [SelectionSort](#SelectionSort) +- [ShellSort](#ShellSort) +- [QuickSort](#QuickSort) +- [HeapSort](#HeapSort) +- [MergeSort](#MergeSort) +- [CountSort](#CountSort) +- [BinarySearch](#BinarySearch) +- [BinaryIterativeSearch](#BinaryIterativeSearch) +- [LinearSearch](#LinearSearch) +- [LRUCache](#LRUCache)
## 文档 ### BubbleSort +

冒泡排序,参数comparator需要实现包lancetconstraints.Comparator。

函数签名: @@ -48,6 +50,7 @@ import ( ```go func BubbleSort[T any](slice []T, comparator lancetconstraints.Comparator) ``` + 示例: ```go @@ -87,6 +90,7 @@ func main() { ``` ### InsertionSort +

插入排序,参数comparator需要实现包lancetconstraints.Comparator。

函数签名: @@ -94,6 +98,7 @@ func main() { ```go func InsertionSort[T any](slice []T, comparator lancetconstraints.Comparator) ``` + 示例: ```go @@ -141,14 +146,14 @@ func main() { algorithm.InsertionSort(peoples, comparator) fmt.Println(peoples) - + // Output: //[{d 8} {b 10} {c 17} {a 20} {e 28}] } ``` - ### SelectionSort +

选择排序,参数comparator需要实现包lancetconstraints.Comparator。

函数签名: @@ -156,6 +161,7 @@ func main() { ```go func SelectionSort[T any](slice []T, comparator lancetconstraints.Comparator) ``` + 示例: ```go @@ -195,6 +201,7 @@ func main() { ``` ### ShellSort +

希尔排序,参数comparator需要实现包lancetconstraints.Comparator。

函数签名: @@ -202,6 +209,7 @@ func main() { ```go func ShellSort[T any](slice []T, comparator lancetconstraints.Comparator) ``` + 示例: ```go @@ -241,6 +249,7 @@ func main() { ``` ### QuickSort +

快速排序,参数comparator需要实现包lancetconstraints.Comparator。

函数签名: @@ -248,6 +257,7 @@ func main() { ```go func QuickSort[T any](slice []T comparator lancetconstraints.Comparator) ``` + 示例: ```go @@ -287,6 +297,7 @@ func main() { ``` ### HeapSort +

堆排序,参数comparator需要实现包lancetconstraints.Comparator。

函数签名: @@ -294,6 +305,7 @@ func main() { ```go func HeapSort[T any](slice []T, comparator lancetconstraints.Comparator) ``` + 示例: ```go @@ -333,6 +345,7 @@ func main() { ``` ### MergeSort +

归并排序,参数comparator需要实现包lancetconstraints.Comparator。

函数签名: @@ -340,6 +353,7 @@ func main() { ```go func MergeSort[T any](slice []T, comparator lancetconstraints.Comparator) ``` + 示例: ```go @@ -379,6 +393,7 @@ func main() { ``` ### CountSort +

计数排序,参数comparator需要实现包lancetconstraints.Comparator。

函数签名: @@ -386,6 +401,7 @@ func main() { ```go func CountSort[T any](slice []T, comparator lancetconstraints.Comparator) []T ``` + 示例: ```go @@ -426,6 +442,7 @@ func main() { ``` ### BinarySearch +

二分递归查找,返回元素索引,未找到元素返回-1,参数comparator需要实现包lancetconstraints.Comparator。

函数签名: @@ -433,6 +450,7 @@ func main() { ```go func BinarySearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) int ``` + 示例: ```go @@ -475,6 +493,7 @@ func main() { ``` ### BinaryIterativeSearch +

二分迭代查找,返回元素索引,未找到元素返回-1,参数comparator需要实现包lancetconstraints.Comparator。

函数签名: @@ -482,6 +501,7 @@ func main() { ```go func BinaryIterativeSearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) int ``` + 示例: ```go @@ -524,6 +544,7 @@ func main() { ``` ### LinearSearch +

基于传入的相等函数线性查找元素,返回元素索引,未找到元素返回-1。

函数签名: @@ -531,6 +552,7 @@ func main() { ```go func LinearSearch[T any](slice []T, target T, equal func(a, b T) bool) int ``` + 示例: ```go @@ -561,6 +583,7 @@ func main() { ``` ### LRUCache +

lru算法实现缓存。

函数签名: @@ -572,6 +595,7 @@ func (l *LRUCache[K, V]) Put(key K, value V) func (l *LRUCache[K, V]) Delete(key K) bool func (l *LRUCache[K, V]) Len() int ``` + 示例: ```go @@ -609,4 +633,4 @@ func main() { // 2 // true } -``` \ No newline at end of file +```