sort

package
v3.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2022 License: MIT Imports: 4 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 Bubble

func Bubble[T constraints.Ordered](arr []T) []T

Bubble is a simple generic definition of Bubble sort algorithm.

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.Number](data []int) []int

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

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