1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-15 10:12:29 +08:00

docs: update sort function doc

This commit is contained in:
dudaodong
2022-04-12 14:45:22 +08:00
parent 5d6f9443fd
commit c960841491
2 changed files with 74 additions and 64 deletions

View File

@@ -21,18 +21,23 @@ import (
<div STYLE="page-break-after: always;"></div> <div STYLE="page-break-after: always;"></div>
## Index ## Index
- [BubbleSort](#BubbleSort) - [Algorithm](#algorithm)
- [CountSort](#CountSort) - [Source](#source)
- [HeapSort](#HeapSort) - [Usage](#usage)
- [InsertionSort](#InsertionSort) - [Index](#index)
- [MergeSort](#MergeSort) - [Documentation](#documentation)
- [QuickSort](#QuickSort) - [<span id="BubbleSort">BubbleSort</span>](#bubblesort)
- [SelectionSort](#SelectionSort) - [<span id="InsertionSort">InsertionSort</span>](#insertionsort)
- [ShellSort](#ShellSort) - [<span id="SelectionSort">SelectionSort</span>](#selectionsort)
- [BinarySearch](#BinarySearch) - [<span id="ShellSort">ShellSort</span>](#shellsort)
- [BinaryIterativeSearch](#BinaryIterativeSearch) - [<span id="QuickSort">QuickSort</span>](#quicksort)
- [LinearSearch](#LinearSearch) - [<span id="HeapSort">HeapSort</span>](#heapsort)
- [LRUCache](#LRUCache) - [<span id="MergeSort">MergeSort</span>](#mergesort)
- [<span id="CountSort">CountSort</span>](#countsort)
- [<span id="BinarySearch">BinarySearch</span>](#binarysearch)
- [<span id="BinaryIterativeSearch">BinaryIterativeSearch</span>](#binaryiterativesearch)
- [<span id="LinearSearch">LinearSearch</span>](#linearsearch)
- [<span id="LRUCache">LRUCache</span>](#lrucache)
<div STYLE="page-break-after: always;"></div> <div STYLE="page-break-after: always;"></div>
@@ -46,7 +51,7 @@ import (
<b>Signature:</b> <b>Signature:</b>
```go ```go
func BubbleSort[T any](slice []T, comparator lancetconstraints.Comparator) []T func BubbleSort[T any](slice []T, comparator lancetconstraints.Comparator)
``` ```
<b>Example:</b> <b>Example:</b>
@@ -76,9 +81,9 @@ func main() {
intSlice := []int{2, 1, 5, 3, 6, 4} intSlice := []int{2, 1, 5, 3, 6, 4}
comparator := &intComparator{} comparator := &intComparator{}
sortedSlice := algorithm.BubbleSort(intSlice, comparator) algorithm.BubbleSort(intSlice, comparator)
fmt.Println(sortedSlice) //[]int{1, 2, 3, 4, 5, 6} fmt.Println(intSlice) //[]int{1, 2, 3, 4, 5, 6}
} }
``` ```
@@ -91,7 +96,7 @@ func main() {
<b>Signature:</b> <b>Signature:</b>
```go ```go
func InsertionSort[T any](slice []T, comparator lancetconstraints.Comparator) []T func InsertionSort[T any](slice []T, comparator lancetconstraints.Comparator)
``` ```
<b>Example:</b> <b>Example:</b>
@@ -141,9 +146,9 @@ func main() {
{Name: "e", Age: 28}, {Name: "e", Age: 28},
} }
comparator := &peopleAgeComparator{} comparator := &peopleAgeComparator{}
sortedPeople := algorithm.InsertionSort(peoples, comparator) algorithm.InsertionSort(peoples, comparator)
fmt.Println(sortedSlice) //[{d 8} {b 10} {c 17} {a 20} {e 28}] fmt.Println(peoples) //[{d 8} {b 10} {c 17} {a 20} {e 28}]
} }
``` ```
@@ -156,7 +161,7 @@ func main() {
<b>Signature:</b> <b>Signature:</b>
```go ```go
func SelectionSort[T any](slice []T, comparator lancetconstraints.Comparator) []T func SelectionSort[T any](slice []T, comparator lancetconstraints.Comparator)
``` ```
<b>Example:</b> <b>Example:</b>
@@ -186,9 +191,9 @@ func main() {
intSlice := []int{2, 1, 5, 3, 6, 4} intSlice := []int{2, 1, 5, 3, 6, 4}
comparator := &intComparator{} comparator := &intComparator{}
sortedSlice := algorithm.SelectionSort(intSlice, comparator) algorithm.SelectionSort(intSlice, comparator)
fmt.Println(sortedSlice) //[]int{1, 2, 3, 4, 5, 6} fmt.Println(intSlice) //[]int{1, 2, 3, 4, 5, 6}
} }
``` ```
@@ -201,7 +206,7 @@ func main() {
<b>Signature:</b> <b>Signature:</b>
```go ```go
func ShellSort[T any](slice []T, comparator lancetconstraints.Comparator) []T func ShellSort[T any](slice []T, comparator lancetconstraints.Comparator)
``` ```
<b>Example:</b> <b>Example:</b>
@@ -231,9 +236,9 @@ func main() {
intSlice := []int{2, 1, 5, 3, 6, 4} intSlice := []int{2, 1, 5, 3, 6, 4}
comparator := &intComparator{} comparator := &intComparator{}
sortedSlice := algorithm.ShellSort(intSlice, comparator) algorithm.ShellSort(intSlice, comparator)
fmt.Println(sortedSlice) //[]int{1, 2, 3, 4, 5, 6} fmt.Println(intSlice) //[]int{1, 2, 3, 4, 5, 6}
} }
``` ```
@@ -246,7 +251,7 @@ func main() {
<b>Signature:</b> <b>Signature:</b>
```go ```go
func QuickSort[T any](slice []T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) []T func QuickSort[T any](slice []T, lowIndex, highIndex int, comparator lancetconstraints.Comparator)
``` ```
<b>Example:</b> <b>Example:</b>
@@ -276,9 +281,9 @@ func main() {
intSlice := []int{2, 1, 5, 3, 6, 4} intSlice := []int{2, 1, 5, 3, 6, 4}
comparator := &intComparator{} comparator := &intComparator{}
sortedSlice := algorithm.QuickSort(intSlice, 0, len(intSlice)-1, comparator) algorithm.QuickSort(intSlice, 0, len(intSlice)-1, comparator)
fmt.Println(sortedSlice) //[]int{1, 2, 3, 4, 5, 6} fmt.Println(intSlice) //[]int{1, 2, 3, 4, 5, 6}
} }
``` ```
@@ -291,7 +296,7 @@ func main() {
<b>Signature:</b> <b>Signature:</b>
```go ```go
func HeapSort[T any](slice []T, comparator lancetconstraints.Comparator) []T func HeapSort[T any](slice []T, comparator lancetconstraints.Comparator)
``` ```
<b>Example:</b> <b>Example:</b>
@@ -321,9 +326,9 @@ func main() {
intSlice := []int{2, 1, 5, 3, 6, 4} intSlice := []int{2, 1, 5, 3, 6, 4}
comparator := &intComparator{} comparator := &intComparator{}
sortedSlice := algorithm.HeapSort(intSlice, comparator) algorithm.HeapSort(intSlice, comparator)
fmt.Println(sortedSlice) //[]int{1, 2, 3, 4, 5, 6} fmt.Println(intSlice) //[]int{1, 2, 3, 4, 5, 6}
} }
``` ```
@@ -336,7 +341,7 @@ func main() {
<b>Signature:</b> <b>Signature:</b>
```go ```go
func MergeSort[T any](slice []T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) []T func MergeSort[T any](slice []T, comparator lancetconstraints.Comparator)
``` ```
<b>Example:</b> <b>Example:</b>
@@ -366,9 +371,9 @@ func main() {
intSlice := []int{2, 1, 5, 3, 6, 4} intSlice := []int{2, 1, 5, 3, 6, 4}
comparator := &intComparator{} comparator := &intComparator{}
sortedSlice := algorithm.MergeSort(intSlice, 0, len(intSlice)-1, comparator) algorithm.MergeSort(intSlice, comparator)
fmt.Println(sortedSlice) //[]int{1, 2, 3, 4, 5, 6} fmt.Println(intSlice) //[]int{1, 2, 3, 4, 5, 6}
} }
``` ```

View File

@@ -21,18 +21,23 @@ import (
<div STYLE="page-break-after: always;"></div> <div STYLE="page-break-after: always;"></div>
## 目录 ## 目录
- [BubbleSort](#BubbleSort) - [Algorithm](#algorithm)
- [CountSort](#CountSort) - [源码](#源码)
- [HeapSort](#HeapSort) - [用法](#用法)
- [InsertionSort](#InsertionSort) - [目录](#目录)
- [MergeSort](#MergeSort) - [文档](#文档)
- [QuickSort](#QuickSort) - [<span id="BubbleSort">BubbleSort</span>](#bubblesort)
- [SelectionSort](#SelectionSort) - [<span id="InsertionSort">InsertionSort</span>](#insertionsort)
- [ShellSort](#ShellSort) - [<span id="SelectionSort">SelectionSort</span>](#selectionsort)
- [BinarySearch](#BinarySearch) - [<span id="ShellSort">ShellSort</span>](#shellsort)
- [BinaryIterativeSearch](#BinaryIterativeSearch) - [<span id="QuickSort">QuickSort</span>](#quicksort)
- [LinearSearch](#LinearSearch) - [<span id="HeapSort">HeapSort</span>](#heapsort)
- [LRUCache](#LRUCache) - [<span id="MergeSort">MergeSort</span>](#mergesort)
- [<span id="CountSort">CountSort</span>](#countsort)
- [<span id="BinarySearch">BinarySearch</span>](#binarysearch)
- [<span id="BinaryIterativeSearch">BinaryIterativeSearch</span>](#binaryiterativesearch)
- [<span id="LinearSearch">LinearSearch</span>](#linearsearch)
- [<span id="LRUCache">LRUCache</span>](#lrucache)
<div STYLE="page-break-after: always;"></div> <div STYLE="page-break-after: always;"></div>
@@ -46,7 +51,7 @@ import (
<b>函数签名:</b> <b>函数签名:</b>
```go ```go
func BubbleSort[T any](slice []T, comparator lancetconstraints.Comparator) []T func BubbleSort[T any](slice []T, comparator lancetconstraints.Comparator)
``` ```
<b>Example:</b> <b>Example:</b>
@@ -76,9 +81,9 @@ func main() {
intSlice := []int{2, 1, 5, 3, 6, 4} intSlice := []int{2, 1, 5, 3, 6, 4}
comparator := &intComparator{} comparator := &intComparator{}
sortedSlice := algorithm.BubbleSort(intSlice, comparator) algorithm.BubbleSort(intSlice, comparator)
fmt.Println(sortedSlice) //[]int{1, 2, 3, 4, 5, 6} fmt.Println(intSlice) //[]int{1, 2, 3, 4, 5, 6}
} }
``` ```
@@ -91,7 +96,7 @@ func main() {
<b>函数签名:</b> <b>函数签名:</b>
```go ```go
func InsertionSort[T any](slice []T, comparator lancetconstraints.Comparator) []T func InsertionSort[T any](slice []T, comparator lancetconstraints.Comparator)
``` ```
<b>Example:</b> <b>Example:</b>
@@ -141,9 +146,9 @@ func main() {
{Name: "e", Age: 28}, {Name: "e", Age: 28},
} }
comparator := &peopleAgeComparator{} comparator := &peopleAgeComparator{}
sortedPeople := algorithm.InsertionSort(peoples, comparator) algorithm.InsertionSort(peoples, comparator)
fmt.Println(sortedSlice) //[{d 8} {b 10} {c 17} {a 20} {e 28}] fmt.Println(intSlice) //[{d 8} {b 10} {c 17} {a 20} {e 28}]
} }
``` ```
@@ -156,7 +161,7 @@ func main() {
<b>函数签名:</b> <b>函数签名:</b>
```go ```go
func SelectionSort[T any](slice []T, comparator lancetconstraints.Comparator) []T func SelectionSort[T any](slice []T, comparator lancetconstraints.Comparator)
``` ```
<b>Example:</b> <b>Example:</b>
@@ -186,9 +191,9 @@ func main() {
intSlice := []int{2, 1, 5, 3, 6, 4} intSlice := []int{2, 1, 5, 3, 6, 4}
comparator := &intComparator{} comparator := &intComparator{}
sortedSlice := algorithm.SelectionSort(intSlice, comparator) algorithm.SelectionSort(intSlice, comparator)
fmt.Println(sortedSlice) //[]int{1, 2, 3, 4, 5, 6} fmt.Println(intSlice) //[]int{1, 2, 3, 4, 5, 6}
} }
``` ```
@@ -201,7 +206,7 @@ func main() {
<b>函数签名:</b> <b>函数签名:</b>
```go ```go
func ShellSort[T any](slice []T, comparator lancetconstraints.Comparator) []T func ShellSort[T any](slice []T, comparator lancetconstraints.Comparator)
``` ```
<b>Example:</b> <b>Example:</b>
@@ -231,9 +236,9 @@ func main() {
intSlice := []int{2, 1, 5, 3, 6, 4} intSlice := []int{2, 1, 5, 3, 6, 4}
comparator := &intComparator{} comparator := &intComparator{}
sortedSlice := algorithm.ShellSort(intSlice, comparator) algorithm.ShellSort(intSlice, comparator)
fmt.Println(sortedSlice) //[]int{1, 2, 3, 4, 5, 6} fmt.Println(intSlice) //[]int{1, 2, 3, 4, 5, 6}
} }
``` ```
@@ -276,9 +281,9 @@ func main() {
intSlice := []int{2, 1, 5, 3, 6, 4} intSlice := []int{2, 1, 5, 3, 6, 4}
comparator := &intComparator{} comparator := &intComparator{}
sortedSlice := algorithm.QuickSort(intSlice, 0, len(intSlice)-1, comparator) algorithm.QuickSort(intSlice, 0, len(intSlice)-1, comparator)
fmt.Println(sortedSlice) //[]int{1, 2, 3, 4, 5, 6} fmt.Println(intSlice) //[]int{1, 2, 3, 4, 5, 6}
} }
``` ```
@@ -321,9 +326,9 @@ func main() {
intSlice := []int{2, 1, 5, 3, 6, 4} intSlice := []int{2, 1, 5, 3, 6, 4}
comparator := &intComparator{} comparator := &intComparator{}
sortedSlice := algorithm.HeapSort(intSlice, comparator) algorithm.HeapSort(intSlice, comparator)
fmt.Println(sortedSlice) //[]int{1, 2, 3, 4, 5, 6} fmt.Println(intSlice) //[]int{1, 2, 3, 4, 5, 6}
} }
``` ```
@@ -336,7 +341,7 @@ func main() {
<b>函数签名:</b> <b>函数签名:</b>
```go ```go
func MergeSort[T any](slice []T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) []T func MergeSort[T any](slice []T, comparator lancetconstraints.Comparator)
``` ```
<b>Example:</b> <b>Example:</b>
@@ -366,9 +371,9 @@ func main() {
intSlice := []int{2, 1, 5, 3, 6, 4} intSlice := []int{2, 1, 5, 3, 6, 4}
comparator := &intComparator{} comparator := &intComparator{}
sortedSlice := algorithm.MergeSort(intSlice, 0, len(intSlice)-1, comparator) algorithm.MergeSort(intSlice, comparator)
fmt.Println(sortedSlice) //[]int{1, 2, 3, 4, 5, 6} fmt.Println(intSlice) //[]int{1, 2, 3, 4, 5, 6}
} }
``` ```