题解 | #排序#
排序
https://www.nowcoder.com/practice/2baf799ea0594abd974d37139de27896
-- Lua代码 function Partition(nums, left, right) key = nums[left] while left < right do while left < right and key <= nums[right] do right = right - 1 end nums[left] = nums[right] while left < right and key >= nums[left] do left = left + 1 end nums[right] = nums[left] end nums[left] = key return left end function QSort(nums, left, right) if left >= right then return end keyPos = Partition(nums, left, right) QSort(nums, left, keyPos - 1) QSort(nums, keyPos + 1, right) end nums = { 4,2,5,1,3 } QSort(nums, 1, #nums) print(table.concat(nums, " "))
https://blog.csdn.net/BingDream/article/details/119875181?spm=1001.2014.3001.5501