Exemple #1
0
func Sort(data sortable.Interface) {
	for i := 0; i < data.Len()-1; i++ {
		for j := i + 1; j > 0 && data.Less(j, j-1); j-- {
			data.Swap(j, j-1)
		}
	}
}
Exemple #2
0
func Sort(data sortable.Interface) {
	for i := 0; i < data.Len(); i++ {
		min := i
		for j := i + 1; j < data.Len(); j++ {
			if data.Less(j, min) {
				min = j
			}
		}
		data.Swap(i, min)
	}
}
Exemple #3
0
func Sort(data sortable.Interface) {
	n := data.Len() - 1
	for i := n / 2; i >= 0; i-- {
		sink(data, i, n)
	}

	for n > 0 {
		data.Swap(0, n)
		n = n - 1
		sink(data, 0, n)
	}
}
Exemple #4
0
func Sort(data sortable.Interface) {
	h := 1
	for h < data.Len()/3 {
		h = 3*h + 1
	}

	for h >= 1 {
		for i := 0; i < data.Len()-h; i = i + h {
			for j := i + h; j > 0 && data.Less(j, j-h); j = j - h {
				data.Swap(j, j-1)
			}
		}
		h = h / 3
	}
}
Exemple #5
0
func Sort(data sortable.Interface) {
	sortable.RandomShuffle(data)
	quickSort(data, 0, data.Len()-1)
}
Exemple #6
0
func Sort(data sortable.Interface) {
	aux := data.AllocateNew()
	mergeSort(data, aux, 0, data.Len()-1)
}