Documentation ¶
Index ¶
- func BinaryIterativeSearch[T any](sortedSlice []T, target T, comparator constraints.Comparator[T]) int
- func BinarySearch[T any](sortedSlice []T, target T, comparator constraints.Comparator[T]) int
- func BubbleSort[T any](arr []T, comparator constraints.Comparator[T])
- func CountSort(arr []int, comparator constraints.Comparator[int])
- func HeapSort[T any](arr []T, comparator constraints.Comparator[T])
- func InsertionSort[T any](arr []T, comparator constraints.Comparator[T])
- func InsertionSortHalf[T any](arr []T, comparator constraints.Comparator[T])
- func LinearSearch[T any](slice []T, target T, equal func(a, b T) bool) int
- func MergeSort[T any](arr []T, comparator constraints.Comparator[T])
- func MergeSortLoop[T any](arr []T, comparator constraints.Comparator[T])
- func QuickSort[T any](arr []T, comparator constraints.Comparator[T])
- func RadixSort(arr []int, comparator constraints.Comparator[int])
- func SelectionSort[T any](arr []T, comparator constraints.Comparator[T])
- func ShellSort[T any](arr []T, comparator constraints.Comparator[T])
- type NumericComparator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BinaryIterativeSearch ¶
func BinaryIterativeSearch[T any](sortedSlice []T, target T, comparator constraints.Comparator[T]) int
BinaryIterativeSearch return the index of target within a sorted slice, use binary search (no recursive). If not found return -1.
func BinarySearch ¶
func BinarySearch[T any](sortedSlice []T, target T, comparator constraints.Comparator[T]) int
BinarySearch return the index of target within a sorted slice, use binary search (recursive call itself). If not found return -1.
func BubbleSort ¶
func BubbleSort[T any](arr []T, comparator constraints.Comparator[T])
BubbleSort applys the bubble sort algorithm to sort the collection, will change the original collection data. stable S(n) = O(1) T(n)max = O(n2) T(n)mean = O(n2)
func CountSort ¶
func CountSort(arr []int, comparator constraints.Comparator[int])
CountSort applys the count sort algorithm to sort the collection, don't change the original collection data. unstable S(n) = O(k) T(n) = O(n+k)
func HeapSort ¶
func HeapSort[T any](arr []T, comparator constraints.Comparator[T])
HeapSort applys the heap sort algorithm to sort the collection, will change the original collection data. unstable S(n) = O(1) T(n) = O(nlog2n)
func InsertionSort ¶
func InsertionSort[T any](arr []T, comparator constraints.Comparator[T])
InsertionSort applys the insertion sort algorithm to sort the collection, will change the original collection data. stable S(n) = O(1) T(n) = O(n2)
func InsertionSortHalf ¶
func InsertionSortHalf[T any](arr []T, comparator constraints.Comparator[T])
func LinearSearch ¶
LinearSearch return the index of target in slice base on equal function. If not found return -1
func MergeSort ¶
func MergeSort[T any](arr []T, comparator constraints.Comparator[T])
MergeSort applys the merge sort algorithm to sort the collection, will change the original collection data. stable S(n) = O(n) O(n) = O(nlog2n)
func MergeSortLoop ¶
func MergeSortLoop[T any](arr []T, comparator constraints.Comparator[T])
func QuickSort ¶
func QuickSort[T any](arr []T, comparator constraints.Comparator[T])
QuickSort quick sorting for slice, lowIndex is 0 and highIndex is len(slice)-1. stable S(n)max = O(n) S(n)mean = O(log2n) T(n)max = O(n2) T(n) = O(nlog2n)
func RadixSort ¶
func RadixSort(arr []int, comparator constraints.Comparator[int])
RadixSort applys the radix sort algorithm to sort the collection, will change the original collection data. stable S(n) = O(r) T(n) = O(d(n+r))
func SelectionSort ¶
func SelectionSort[T any](arr []T, comparator constraints.Comparator[T])
SelectionSort applys the selection sort algorithm to sort the collection, will change the original collection data. unstable S(n) = O(1) T(n) = O(n2)
func ShellSort ¶
func ShellSort[T any](arr []T, comparator constraints.Comparator[T])
ShellSort applys the shell sort algorithm to sort the collection, will change the original collection data. ubstable S(n) = O(1) T(n) = O(n2)
Types ¶
type NumericComparator ¶
func (NumericComparator[T]) Compare ¶
func (nc NumericComparator[T]) Compare(lhs, rhs T) int