gosort

package
v0.0.0-...-c4ba0da Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2019 License: MIT Imports: 9 Imported by: 0

README

Golang + Sort = goSort

Golang implementation of sorting algothims.
You can see an extended doc in godocs.

  • Install it with:

    go get github.com/jenazads/goalgos/sort
    

Sorting Algorithms

In this section I introduce Sorting Algorithms

Simple Sort
Algorithm Best Case Average Case Worst case
GnomeSort O(n) O(n²) O(n²)
InsertionSort O(n) O(n²) O(n²)
SelectionSort O(n²) O(n²) O(n²)
SlowSort O(n^(log(n)/2)) O(np) O(np)
SillySort O(n^(a log n)) O(n^(a log n)) O(n^(a log n))
LibrarySort O(n) O(nlog(n)) O(n²)
PatienceSort O(n) O(nlog(n)) O(nlog(n))
Efficient Sort
Algorithm Best Case Average Case Worst case
MergeSort O(nlog(n)) O(nlog(n)) O(nlog(n))
QuickSort O(nlog(n)) O(nlog(n)) O(n²)
HeapSort O(nlog(n)) O(nlog(n)) O(nlog(n))
TimSort O(n) O(nlog(n)) O(nlog(n))
TreeSort O(n) O(nlog(n)) O(nlog(n))
IntroSort O(nlog(n)) O(nlog(n)) O(nlog(n))
TournamentSort O(nlog(n)) O(nlog(n)) O(nlog(n))
SmoothSort O(n) O(nlog(n)) O(nlog(n))
BlockSort O(n) O(nlog(n)) O(nlog(n))
StrandSort O(n) O(n²) O(n²)
Swap Sort
Algorithm Best Case Average Case Worst case
BubbleSort O(n) O(n²) O(n²)
CockTailSort O(n) O(n²) O(n²)
ShellSort O(n) O(n(log(n))²) O((nlog(n))²)
CombSort O(nlog(n)) O(n²) O(n²)
CycleSort O(n²) O(n²) O(n²)
CircleSort O() O() O()
PermutationSort O() O() O()
Distribution Sort
  • Note: k in Bucket Sort means number of buckets.
  • Note: k in CountingSort means the number of different numbers in array.
  • Note: k in PigeonHoleSort means the number of range number.
  • Note: k in RadixSort means the number of range number.
  • Note: k in SpreadSort means the number of range number and d means the digits of the numbers.
  • Notes: Couting sort and Radix sort is only for integers.
Algorithm Best Case Average Case Worst case
BucketSort O(n+k) O(n+k) O(n²)
ShuffleSort O(n+k) O(n+k) O(n²)
CountingSort O(n+k) O(n+k) O(n+k)
PigeonHoleSort O(n+k) O(n+k) O(n+k)
RadixSort O(n.k) O(n.k) O(nk)
SpreadSort O(n) O(n.k/d) O(n.(k/s+d))
BurstSort O(n) O(n.k/d) O(n.k/d)
FlashSort O(n) O(n.+r) O(n²)
PostmanSort O(n) O(n.k/d) O(n.k/d)
ProxmapSort O(n) O(n) O(n²)
Hard Sort
Algorithm Best Case Average Case Worst case
PancakeSort O(n) O(n) O(n)
BitonicSort O(log²(n)) O(log²(n)) O(log²(n))
BogoSort O(n) O(n.n!) O(Inf)
StoogeSort O(n^(log(3)/log(1.5))) O(n^(log(3)/log(1.5))) O(n^(log(3)/log(1.5)))
BeadSort O(n) O(Sum (ai)) O(Sum (ai))
SpaghettiSort O(n) O(n) O(n)
NetworkSort O(log²(n)) O(log²(n)) O(log²(n))
Parallel Sort
  • Note: t in SleepSort means the time of seconds sleeped by the number value.
Algorithm Best Case Average Case Worst case
BrickSort O(n) O(n²) O(n²)
SleepSort O(nt) O(nt) O(nt)
SampleSort O(n) O(Sum (ai)) O(Sum (ai))
CubeSort O(n) O(nlog(n)) O(nlog(n))

Documentation

Overview

Package GoSort functions and other helpful libraries for Sorting Algorithms

See Readme.md for more info.

Example (SortingAlgorithms)
begin := 24
end := 34

arr := []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ := gosort.NewGoSort(arr, goutils.IntComparator)
fmt.Println("GnomeSort")
sortObject.GnomeSort(begin, sortObject.Len()-end)
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSort(arr, goutils.IntComparator)
fmt.Println("InsertionSort")
sortObject.InsertionSort(begin, sortObject.Len()-end)
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSort(arr, goutils.IntComparator)
fmt.Println("SlowSort")
sortObject.SlowSort(begin, sortObject.Len()-end)
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSort(arr, goutils.IntComparator)
fmt.Println("SelectionSort")
sortObject.SelectionSort(begin, sortObject.Len()-end)
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSort(arr, goutils.IntComparator)
fmt.Println("SillySort")
sortObject.SillySort(begin, sortObject.Len()-end)
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSort(arr, goutils.IntComparator)
fmt.Println("QuickSort")
sortObject.QuickSort(begin, sortObject.Len()-end)
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSort(arr, goutils.IntComparator)
fmt.Println("MergeSort")
sortObject.MergeSort(begin, sortObject.Len()-end)
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSort(arr, goutils.IntComparator)
fmt.Println("HeapSort -> revisar el sub array")
sortObject.HeapSort(begin, sortObject.Len()-end)
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSort(arr, goutils.IntComparator)
fmt.Println("TimSort")
sortObject.TimSort(begin, sortObject.Len()-end)
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSortOp(arr, goutils.IntComparator, goutils.IntOperator)
fmt.Println("TreeSort")
sortObject.TreeSort(begin, sortObject.Len()-end, func(a interface{}) interface{} {
	return a
})
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSort(arr, goutils.IntComparator)
fmt.Println("BubbleSort")
sortObject.BubbleSort(begin, sortObject.Len()-end)
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSort(arr, goutils.IntComparator)
fmt.Println("CockTailSort")
sortObject.CockTailSort(begin, sortObject.Len()-end)
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSort(arr, goutils.IntComparator)
fmt.Println("ShellSort")
sortObject.ShellSort(begin, sortObject.Len()-end)
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSort(arr, goutils.IntComparator)
fmt.Println("CombSort")
sortObject.CombSort(begin, sortObject.Len()-end)
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSort(arr, goutils.IntComparator)
fmt.Println("CycleSort")
sortObject.CycleSort(begin, sortObject.Len()-end)
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSort(arr, goutils.IntComparator)
fmt.Println("CircleSort")
sortObject.CircleSort(begin, sortObject.Len()-end)
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSort(arr, goutils.IntComparator)
fmt.Println("BrickSort")
sortObject.BrickSort(begin, sortObject.Len()-end)
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSort(arr, goutils.IntComparator)
fmt.Println("SleepSort -> revisar el algoritmo")
sortObject.SleepSort(begin, sortObject.Len()-end)
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSortOp(arr, goutils.IntComparator, goutils.IntOperator)
fmt.Println("BucketSort")
sortObject.BucketSort(begin, sortObject.Len()-end)
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSortOp(arr, goutils.IntComparator, goutils.IntOperator)
fmt.Println("PigeonHoleSort")
sortObject.PigeonHoleSort(begin, sortObject.Len()-end)
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSortOp(arr, goutils.IntComparator, goutils.IntOperator)
fmt.Println("CountingSort")
sortObject.CountingSort(begin, sortObject.Len()-end)
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSortOp(arr, goutils.IntComparator, goutils.IntOperator)
fmt.Println("StoogeSort")
sortObject.StoogeSort(begin, sortObject.Len()-end)
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSortOp(arr, goutils.IntComparator, goutils.IntOperator)
fmt.Println("PancakeSort")
sortObject.PancakeSort(begin, sortObject.Len()-end)
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSortOp(arr, goutils.IntComparator, goutils.IntOperator)
fmt.Println("IntroSort")
sortObject.IntroSort(begin, sortObject.Len()-end)
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSortOp(arr, goutils.IntComparator, goutils.IntOperator)
fmt.Println("BitonicSort")
sortObject.BitonicSort(0, sortObject.Len())
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSortOp(arr, goutils.IntComparator, goutils.IntOperator)
fmt.Println("PermutationSort")
sortObject.PermutationSort(begin, sortObject.Len()-end)
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")

arr = []interface{}{10, 6, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 10, 3, 5, 8, 8, 3, 2, 7, 4, 8, 8, 3, 2, 7, 4, 6, 8, 8, 3, 2, 7, 4, 9, 11, 10, 9, 6, 8, 8, 3, 5, 5, 7, 8, 15, 49, 65, 2}

sortObject, _ = gosort.NewGoSortOp(arr, goutils.IntComparator, goutils.IntOperator)
fmt.Println("BogoSort")
sortObject.BogoSort(begin, sortObject.Len()-end)
fmt.Println("Is Ordered ? ", arr)
fmt.Println("Is Ordered ? ", sortObject.IsSorted(), "\n\n")
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	GoSortEmptyArray = errors.New("Invalid Empty Array to Sort.\n")
)

Functions

This section is empty.

Types

type GoSort

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

GoSort object

func NewGoSort

func NewGoSort(arr []interface{}, comp goutils.TypeComparator) (*GoSort, error)

new GoSort

func NewGoSortOp

func NewGoSortOp(arr []interface{}, comp goutils.TypeComparator, op goutils.TypeOperator) (*GoSort, error)

func (*GoSort) BitonicSort

func (s *GoSort) BitonicSort(low, high int)

Call BitonicSort from HardSort package Run as BitonicSort(begin, end), (end-high) must be a power of 2.

func (*GoSort) BogoSort

func (s *GoSort) BogoSort(low, high int)

Call PancakeSort from HardSort package Run as PancakeSort(begin, end)

func (*GoSort) BrickSort

func (s *GoSort) BrickSort(low, high int)

Call BrickSort from ParallelSort package Run as BrickSort(begin, end)

func (*GoSort) BubbleSort

func (s *GoSort) BubbleSort(low, high int)

Call BubbleSort from SwapSort package Run as BubbleSort(begin, end)

func (*GoSort) BucketSort

func (s *GoSort) BucketSort(low, high int)

Call BucketSort from DistributionSort package Run as BucketSort(begin, end)

func (*GoSort) CircleSort

func (s *GoSort) CircleSort(low, high int)

Call CircleSort from SwapSort package Run as CircleSort(begin, end)

func (*GoSort) CockTailSort

func (s *GoSort) CockTailSort(low, high int)

Call CockTailSort from SwapSort package Run as CockTailSort(begin, end)

func (*GoSort) CombSort

func (s *GoSort) CombSort(low, high int)

Call CombSort from SwapSort package Run as CombSort(begin, end)

func (*GoSort) CountingSort

func (s *GoSort) CountingSort(low, high int)

Call CountingSort from DistributionSort package Run as CountingSort(begin, end)

func (*GoSort) CycleSort

func (s *GoSort) CycleSort(low, high int)

Call CycleSort from SwapSort package Run as CycleSort(begin, end)

func (*GoSort) EqualsThan

func (s *GoSort) EqualsThan(i, j int) bool

return if is equals

func (*GoSort) FindMaxElementAndIndex

func (s *GoSort) FindMaxElementAndIndex() (interface{}, int)

find the max element and respective index

func (*GoSort) FindMinElementAndIndex

func (s *GoSort) FindMinElementAndIndex() (interface{}, int)

find the min element and respective index

func (*GoSort) GnomeSort

func (s *GoSort) GnomeSort(low, high int)

Call GnomeSort from SimpleSort package Run as GnomeSort(begin, end)

func (*GoSort) GoSort

func (s *GoSort) GoSort()

Sort sorts values (in-place) with respect to the given comparator.

func (*GoSort) GreaterEqualsThan

func (s *GoSort) GreaterEqualsThan(i, j int) bool

return if is greater or equals

func (*GoSort) GreaterThan

func (s *GoSort) GreaterThan(i, j int) bool

return if is greater

func (*GoSort) HeapSort

func (s *GoSort) HeapSort(low, high int)

Call HeapSort from EfficientSort package Run as HeapSort(begin, end)

func (*GoSort) InsertionSort

func (s *GoSort) InsertionSort(low, high int)

Call InsertionSort from SimpleSort package Run as InsertionSort(begin, end)

func (*GoSort) IntroSort

func (s *GoSort) IntroSort(low, high int)

Call IntroSort from EfficientSort package Run as IntroSort(begin, end)

func (*GoSort) IsSorted

func (s *GoSort) IsSorted() bool

return True if is sorted

func (*GoSort) IsSortedPart

func (s *GoSort) IsSortedPart(begin, end int) bool

return True if is sorted in this part

func (*GoSort) Len

func (s *GoSort) Len() int

return the len of array

func (*GoSort) Less

func (s *GoSort) Less(i, j int) bool

return if is less

func (*GoSort) LessEqualsThan

func (s *GoSort) LessEqualsThan(i, j int) bool

return if is less or equals

func (*GoSort) LessThan

func (s *GoSort) LessThan(i, j int) bool

return if is less

func (*GoSort) MergeSort

func (s *GoSort) MergeSort(low, high int)

Call MergeSort from EfficientSort package Run as MergeSort(begin, end)

func (*GoSort) PancakeSort

func (s *GoSort) PancakeSort(low, high int)

Call PancakeSort from HardSort package Run as PancakeSort(begin, end)

func (*GoSort) PermutationSort

func (s *GoSort) PermutationSort(low, high int)

Call PermutationSort from SwapSort package Run as PermutationSort(begin, end)

func (*GoSort) PigeonHoleSort

func (s *GoSort) PigeonHoleSort(low, high int)

Call PigeonHoleSort from DistributionSort package Run as PigeonHoleSort(begin, end)

func (*GoSort) QuickSort

func (s *GoSort) QuickSort(low, high int)

Call QuickSort from EfficientSort package Run as QuickSort(begin, end)

func (*GoSort) SelectionSort

func (s *GoSort) SelectionSort(low, high int)

Call SelectionSort from SimpleSort package Run as SelectionSort(begin, end)

func (*GoSort) ShellSort

func (s *GoSort) ShellSort(low, high int)

Call ShellSort from SwapSort package Run as ShellSort(begin, end)

func (*GoSort) ShuffleSort

func (s *GoSort) ShuffleSort(low, high int)

Call BucketSort from DistributionSort package Run as BucketSort(begin, end)

func (*GoSort) SillySort

func (s *GoSort) SillySort(low, high int)

Call SillySort from SimpleSort package Run as SillySort(begin, end)

func (*GoSort) SleepSort

func (s *GoSort) SleepSort(low, high int)

Call SleepSort from ParallelSort package Run as SleepSort(begin, end)

func (*GoSort) SlowSort

func (s *GoSort) SlowSort(low, high int)

Call SlowSort from SimpleSort package Run as SlowSort(begin, end)

func (*GoSort) StoogeSort

func (s *GoSort) StoogeSort(low, high int)

Call StoogeSort from HardSort package Run as StoogeSort(begin, end)

func (*GoSort) SubArray

func (s *GoSort) SubArray(low, high int) *GoSort

return sub array

func (*GoSort) Swap

func (s *GoSort) Swap(i, j int)

swap elements

func (*GoSort) TimSort

func (s *GoSort) TimSort(low, high int)

Call TimSort from EfficientSort package Run as TimSort(begin, end)

func (*GoSort) TreeSort

func (s *GoSort) TreeSort(low, high int, f func(interface{}) interface{})

Call TreeSort from EfficientSort package Run as TreeSort(begin, end)

Directories

Path Synopsis
Package of Distribution Sort Algorithms See Readme.md for more info.
Package of Distribution Sort Algorithms See Readme.md for more info.
Package of Efficient Sort Algorithms See Readme.md for more info.
Package of Efficient Sort Algorithms See Readme.md for more info.
Package of Hard Sort Algorithms See Readme.md for more info.
Package of Hard Sort Algorithms See Readme.md for more info.
Package of Parallel Sort Algorithms See Readme.md for more info.
Package of Parallel Sort Algorithms See Readme.md for more info.
Package of Simple Sort Algorithms See Readme.md for more info.
Package of Simple Sort Algorithms See Readme.md for more info.
Package of Swap Sort Algorithms See Readme.md for more info.
Package of Swap Sort Algorithms See Readme.md for more info.

Jump to

Keyboard shortcuts

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