Documentation
¶
Overview ¶
Package sorting provides sorting algorithms that operate on generic slices.
Index ¶
- Variables
- func BubbleSort[T constraints.Ordered](d []T)
- func InsertionSort[T constraints.Ordered](d []T)
- func MergeSort[T constraints.Ordered](d []T)
- func QuickSort[T constraints.Ordered](d []T)
- func RandomFloat64Slice(n int) []float64
- func RandomIntSlice(n int) []int
- func RandomStringSlice(n int) []string
- func SelectionSort[T constraints.Ordered](d []T)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var SliceLength = flag.Int("slice_length", 1000, "length of slices to test sorting on")
Functions ¶
func BubbleSort ¶
func BubbleSort[T constraints.Ordered](d []T)
BubbleSort performs an in-place bubble sort on the slice d
Example ¶
ExampleBubbleSort calls BubbleSort on the slice [5, 4, 3, 2, 1] and expects output of [1 2 3 4 5]
s := []int{5, 4, 3, 2, 1} BubbleSort(s) fmt.Println(s)
Output: [1 2 3 4 5]
func InsertionSort ¶
func InsertionSort[T constraints.Ordered](d []T)
InsertionSort performs an in-place insertion sort on the slice d
Example ¶
ExampleInsertionSort calls InsertionSort on the slice [5, 4, 3, 2, 1] and expects output of [1 2 3 4 5]
s := []int{5, 4, 3, 2, 1} InsertionSort(s) fmt.Println(s)
Output: [1 2 3 4 5]
func MergeSort ¶
func MergeSort[T constraints.Ordered](d []T)
MergeSort performs an in-place merge sort on the slice d
Example ¶
ExampleMergeSort calls MergeSort on the slice [5, 4, 3, 2, 1] and expects output of [1 2 3 4 5]
s := []int{5, 4, 3, 2, 1} MergeSort(s) fmt.Println(s)
Output: [1 2 3 4 5]
func QuickSort ¶
func QuickSort[T constraints.Ordered](d []T)
QuickSort performs an in-place quick sort on the slice d
Example ¶
ExampleQuickSort calls QuickSort on the slice [5, 4, 3, 2, 1] and expects output of [1 2 3 4 5]
s := []int{5, 4, 3, 2, 1} QuickSort(s) fmt.Println(s)
Output: [1 2 3 4 5]
func RandomFloat64Slice ¶
func RandomIntSlice ¶
func RandomStringSlice ¶
func SelectionSort ¶
func SelectionSort[T constraints.Ordered](d []T)
SelectionSort performs an in-place selection sort on the slice d
Example ¶
ExampleSelectionSort calls SelectionSort on the slice [5, 4, 3, 2, 1] and expects output of [1 2 3 4 5]
s := []int{5, 4, 3, 2, 1} SelectionSort(s) fmt.Println(s)
Output: [1 2 3 4 5]
Types ¶
This section is empty.