主要想法和快速排序一致,不同的是将某一维度作为索引,该索引位置修改了,则对应的原始数据也按照对应的维度进行修改即可,以下例子为二维数组的第一个维度进行的一个快速排序
输入的nums_arrays
nums_arrays = [[1,3],[4,2],[3,5]]
输出的结果[[1, 3], [3, 5], [4, 2]]
def fuction(nums_array,choose):
nums = [x[choose] for x in nums_array]
def quickSort(nums_array,nums,start,end):
if start < end:
mid = nums[start]
left = start+1
right = end
while left <= right:
while left <= right and nums[left] <= mid:
left += 1
while left <= right and nums[right] >= mid:
&nb

这篇博客介绍如何使用Python实现对二维数组的某一维度进行快速排序。以输入二维数组nums_arrays=[[1,3],[4,2],[3,5]]为例,通过对第一个维度排序,得到[[1, 3], [3, 5], [4, 2]]的结果。通过定义quickSort函数,实现了排序过程,并保持原始数组对应关系不变。"
80115318,5278933,"Struts迭代器遍历List总结:String, List<String>, Entity, List<Entity>
最低0.47元/天 解锁文章
4680

被折叠的 条评论
为什么被折叠?



