sort

package
v0.0.0-...-a4a72b7 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package sort a package for demonstrating sorting algorithms in Go

Index

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 Merge

func Merge[T constraints.Ordered](items []T) []T

Merge Perform merge sort on a slice

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 Partition

func Partition[T constraints.Ordered](arr []T, low, high int) int

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 Comparable interface {
	Idx() int
	More(any) bool
}

type MaxHeap

type MaxHeap struct {
	// contains filtered or unexported fields
}

func (MaxHeap) Heapify

func (h MaxHeap) Heapify()

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) Size

func (h MaxHeap) Size() int

func (MaxHeap) Update

func (h MaxHeap) Update(i Comparable)

Jump to

Keyboard shortcuts

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