sortutils

package
v0.0.0-...-c01e8ca Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sort

func Sort[T cmp.Ordered](x []T, algo Algorithm)

Sort sorts x using the chosen algorithm with natural (ordered) comparison.

func SortFunc

func SortFunc[T any](x []T, less func(a, b T) bool, algo Algorithm)

SortFunc sorts x using the chosen algorithm with a custom less function. less(a,b) should return true if a < b.

Types

type Algorithm

type Algorithm int
const (
	QuickSort     Algorithm = iota // Unstable, in-place, average O(n log n)
	MergeSort                      // Stable, O(n log n), extra memory
	HeapSort                       // Unstable, in-place, O(n log n)
	InsertionSort                  // Stable, good for small/near-sorted, O(n^2)
	SelectionSort                  // Unstable, O(n^2)
	BubbleSort                     // Stable (with swap flag), O(n^2)
)

Jump to

Keyboard shortcuts

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