funcSort(arr []int, start, end int) { if start < end { left, right := start, end pivot := arr[(start+end)/2] for left <= right { for arr[left] < pivot { left++ } for arr[right] > pivot { right-- } if left <= right { arr[left], arr[right] = arr[right], arr[left] left++ right-- } }
if start < right { Sort(arr, start, right) } if end > left { Sort(arr, left, end) } } }
funcQuickSort2(arr []int) { iflen(arr) < 2 { return } start, end := 0, len(arr)-1 left, right := start, end pivot := arr[(start+end)/2] for left <= right { for arr[left] < pivot { left++ } for arr[right] > pivot { right-- } if left <= right { arr[left], arr[right] = arr[right], arr[left] left++ right-- } } if start < right { QuickSort2(arr[:right+1]) } if end > left { QuickSort2(arr[left:]) } }