heap_sort

package module
v0.0.0-...-ddc543f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2022 License: MIT Imports: 3 Imported by: 0

README

堆排序(Heap Sort)

一、安装

go get -u github.com/golang-infrastructure/go-heap-sort

二、示例代码

package main

import (
	"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

对元素类型为可比较类型的切片进行正序排序

func Sort[T gtypes.Ordered](slice []T)

对元素类型为可比较类型的切片进行逆向排序

func ReverseSort[T gtypes.Ordered](slice []T) 

使用自定义的比较器对切片进行排序,如果需要逆序可以自行控制比较器的比较规则

func SortByComparator[T any](slice []T, comparator compare_anything.Comparator[T])

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReverseSort

func ReverseSort[T gtypes.Ordered](slice []T)

ReverseSort 对元素类型为可比较类型的切片进行逆向排序

func Sort

func Sort[T gtypes.Ordered](slice []T)

Sort 对元素类型为可比较类型的切片进行正序排序

func SortByComparator

func SortByComparator[T any](slice []T, comparator compare_anything.Comparator[T])

SortByComparator 使用自定义的比较器对切片进行排序,如果需要逆序可以自行控制比较器的比较规则

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL