- def partition(data, front, back)
- lastS1 = front
- pivot = data[front]
- frontUnknown = front + 1
- while frontUnknown <= last do
- if data[frontUnknown] < pivot
- backS1 += 1
- data.swap(frontUnknown, backS1)
- end
- frontUnknown += 1
- end
- data.swap(front, backS1)
- backS1
- end
- def quicksort(data, front = 0, back = data.size - 1)
- if front < back
- pivotIndex = partition(data, front, back)
- quicksort(data, front, pivotIndex - 1)
- quicksort(data, pivotIndex + 1, back)
- end
- end
- #该片段来自于http://www.codesnippet.cn/detail/250420133042.html
来源: http://www.codesnippet.cn/detail/250420133042.html