https://github.com/golang-infrastructure/go-heap-sort
Heap Sort 堆排序
https://github.com/golang-infrastructure/go-heap-sort
heap-sort sorting-algorithms
Last synced: 3 months ago
JSON representation
Heap Sort 堆排序
- Host: GitHub
- URL: https://github.com/golang-infrastructure/go-heap-sort
- Owner: golang-infrastructure
- License: mit
- Created: 2022-12-08T19:28:11.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-12-15T15:30:14.000Z (over 2 years ago)
- Last Synced: 2025-01-18T16:11:02.023Z (5 months ago)
- Topics: heap-sort, sorting-algorithms
- Language: Go
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 堆排序(Heap Sort)
# 一、安装
```bash
go get -u github.com/golang-infrastructure/go-heap-sort
```# 二、示例代码
```go
package mainimport (
"fmt"
heap_sort "github.com/golang-infrastructure/go-heap-sort"
)func main() {
slice := []int{100, 2, 1, 10}
heap_sort.Sort(slice)
fmt.Println(slice)
// Output:
// [1 2 10 100]}
```# 三、API
对元素类型为可比较类型的切片进行正序排序
```go
func Sort[T gtypes.Ordered](slice []T)
```对元素类型为可比较类型的切片进行逆向排序
```go
func ReverseSort[T gtypes.Ordered](slice []T)
```使用自定义的比较器对切片进行排序,如果需要逆序可以自行控制比较器的比较规则
```go
func SortByComparator[T any](slice []T, comparator compare_anything.Comparator[T])
```