Documentation ¶
Overview ¶
Package sort a package for demonstrating sorting algorithms in Go
Index ¶
- func BinaryInsertion[T constraints.Ordered](arr []T) []T
- func Bogo[T constraints.Number](arr []T) []T
- func Bubble[T constraints.Ordered](arr []T) []T
- func Bucket[T constraints.Number](arr []T) []T
- func Cocktail[T constraints.Ordered](arr []T) []T
- func Comb[T constraints.Ordered](data []T) []T
- func Count[T constraints.Integer](data []T) []T
- func Cycle[T constraints.Number](arr []T) []T
- func Exchange[T constraints.Ordered](arr []T) []T
- func HeapSort[T constraints.Ordered](slice []T) []T
- func ImprovedSimple[T constraints.Ordered](arr []T) []T
- func Insertion[T constraints.Ordered](arr []T) []T
- func Merge[T constraints.Ordered](items []T) []T
- func MergeIter[T constraints.Ordered](items []T) []T
- func Pancake[T constraints.Ordered](arr []T) []T
- func ParallelMerge[T constraints.Ordered](items []T) []T
- func Partition[T constraints.Ordered](arr []T, low, high int) int
- func Patience[T constraints.Ordered](arr []T) []T
- func Pigeonhole[T constraints.Integer](arr []T) []T
- func Quicksort[T constraints.Ordered](arr []T) []T
- func QuicksortRange[T constraints.Ordered](arr []T, low, high int)
- func RadixSort[T constraints.Integer](arr []T) []T
- func Selection[T constraints.Ordered](arr []T) []T
- func Shell[T constraints.Ordered](arr []T) []T
- func Simple[T constraints.Ordered](arr []T) []T
- func Timsort[T constraints.Ordered](data []T) []T
- type Comparable
- type MaxHeap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BinaryInsertion ¶
func BinaryInsertion[T constraints.Ordered](arr []T) []T
func Bogo ¶
func Bogo[T constraints.Number](arr []T) []T
func Bubble ¶
func Bubble[T constraints.Ordered](arr []T) []T
Bubble is a simple generic definition of Bubble sort algorithm.
func Bucket ¶
func Bucket[T constraints.Number](arr []T) []T
Bucket sorts a slice. It is mainly useful when input is uniformly distributed over a range.
func Cocktail ¶
func Cocktail[T constraints.Ordered](arr []T) []T
Cocktail sort is a variation of bubble sort, operating in two directions (beginning to end, end to beginning)
func Comb ¶
func Comb[T constraints.Ordered](data []T) []T
Comb is a simple sorting algorithm which is an improvement of the bubble sorting algorithm.
func Count ¶
func Count[T constraints.Integer](data []T) []T
func Cycle ¶
func Cycle[T constraints.Number](arr []T) []T
Cycle sort is an in-place, unstable sorting algorithm that is particularly useful when sorting arrays containing elements with a small range of values. It is theoretically optimal in terms of the total number of writes to the original array.
func Exchange ¶
func Exchange[T constraints.Ordered](arr []T) []T
func HeapSort ¶
func HeapSort[T constraints.Ordered](slice []T) []T
func ImprovedSimple ¶
func ImprovedSimple[T constraints.Ordered](arr []T) []T
ImprovedSimple is a improve SimpleSort by skipping an unnecessary comparison of the first and last. This improved version is more similar to implementation of insertion sort
func Insertion ¶
func Insertion[T constraints.Ordered](arr []T) []T
func MergeIter ¶
func MergeIter[T constraints.Ordered](items []T) []T
func Pancake ¶
func Pancake[T constraints.Ordered](arr []T) []T
Pancake sorts a slice using flip operations, where flip refers to the idea of reversing the slice from index `0` to `i`.
func ParallelMerge ¶
func ParallelMerge[T constraints.Ordered](items []T) []T
ParallelMerge Perform merge sort on a slice using goroutines
func Patience ¶
func Patience[T constraints.Ordered](arr []T) []T
func Pigeonhole ¶
func Pigeonhole[T constraints.Integer](arr []T) []T
Pigeonhole sorts a slice using pigeonhole sorting algorithm. NOTE: To maintain time complexity O(n + N), this is the reason for having only Integer constraint instead of Ordered.
func Quicksort ¶
func Quicksort[T constraints.Ordered](arr []T) []T
Quicksort Sorts the entire array
func QuicksortRange ¶
func QuicksortRange[T constraints.Ordered](arr []T, low, high int)
QuicksortRange Sorts the specified range within the array
func RadixSort ¶
func RadixSort[T constraints.Integer](arr []T) []T
func Selection ¶
func Selection[T constraints.Ordered](arr []T) []T
func Shell ¶
func Shell[T constraints.Ordered](arr []T) []T
func Simple ¶
func Simple[T constraints.Ordered](arr []T) []T
func Timsort ¶
func Timsort[T constraints.Ordered](data []T) []T
Timsort is a simple generic implementation of Timsort algorithm.
Types ¶
type Comparable ¶
type MaxHeap ¶
type MaxHeap struct {
// contains filtered or unexported fields
}
func (*MaxHeap) Init ¶
func (h *MaxHeap) Init(slice []Comparable)
func (*MaxHeap) Pop ¶
func (h *MaxHeap) Pop() Comparable
func (*MaxHeap) Push ¶
func (h *MaxHeap) Push(i Comparable)
func (MaxHeap) Update ¶
func (h MaxHeap) Update(i Comparable)
Source Files ¶
- binaryinsertionsort.go
- bogosort.go
- bubblesort.go
- bucketsort.go
- cocktailsort.go
- combSort.go
- countingsort.go
- cyclesort.go
- doc.go
- exchangesort.go
- heapsort.go
- insertionsort.go
- mergesort.go
- pancakesort.go
- patiencesort.go
- pigeonholesort.go
- quicksort.go
- radixsort.go
- selectionsort.go
- shellsort.go
- simplesort.go
- timsort.go