func insertionSort(array []int) { for i := 1; i < len(array)-1; i++ { for j := i; j > 0 && array[j] < array[j-1]; j-- { algoutils.Swap(array, j, j-1) } } }
func selectionSort(array []int) { for i := 0; i < len(array)-1; i++ { min := i for j := i + 1; j < len(array)-1; j++ { if array[j] < array[min] { min = j } } algoutils.Swap(array, i, min) } }
func bubbleSort(arrayzor []int) { swapped := true for swapped { swapped = false for i := 0; i < len(arrayzor)-1; i++ { if arrayzor[i+1] < arrayzor[i] { algoutils.Swap(arrayzor, i, i+1) swapped = true } } } }
func shellSort(array []int) { h := 1 for h < len(array) { h = 3*h + 1 } for h >= 1 { for i := h; i < len(array); i++ { for j := i; j >= h && array[j] < array[j-h]; j = j - h { algoutils.Swap(array, j, j-h) } } h = h / 3 } }