package sortfunc
// QSort : quickly sort int[] dat
func qSort(vals []int, left, right int) (err error) {
temp := vals[left]
p := left
i, j := left, right
for i <= j {
for j >= p && vals[j] >= temp {
j--
}
if j >= p {
vals[p] = vals[j]
p = j
}
for i <= p && vals[i] <= temp {
i++
}
if i <= p {
vals[p] = vals[i]
p = i
}
}
vals[p] = temp
if p-left > 1 {
qSort(vals, left, p-1)
}
if right-p > 1 {
qSort(vals, p+1, right)
}
return nil
}
// QSort : quick sort
func QSort(vals []int) (err error) {
qSort(vals, 0, len(vals)-1)
return
}