RosettaCodeData/Task/Quickselect-algorithm/Ring/quickselect-algorithm.ring

21 lines
634 B
Text
Raw Normal View History

2016-12-05 23:44:36 +01:00
aList = [9, 8, 7, 6, 5, 0, 1, 2, 3, 4]
see partition(aList, 9, 4, 2) + nl
func partition list, left, right, pivotIndex
2018-06-22 20:57:24 +00:00
pivotValue = list[pivotIndex]
temp = list[pivotIndex]
list[pivotIndex] = list[right]
list[right] = temp
storeIndex = left
for i = left to right-1
if list[i] < pivotValue
temp = list[storeIndex]
list[storeIndex] = list[i]
list[i] = temp
storeIndex++ ok
temp = list[right]
list[right] = list[storeIndex]
list[storeIndex] = temp
next
return storeIndex