#!/usr/bin/python
# -*- coding: utf-8 -*-
# @Time :
# @Author : liyi
# @File :
# 在快排的同时按同样的排序算法对另一个数组进行操作
def quick_sort(array, cid_list, left, right):
if left >= right:
return [array,cid_list]
low = left
high = right
key = array[low]
cid_key = cid_list[low]
while left < right:
while left < right and array[right] > key:
right -= 1
array[left] = array[right]
cid_list[left] = cid_list[right]
while left < right and array[left] <= key:
left += 1
array[right] = array[left]
cid_list[right] = cid_list[left]
array[right] = key
cid_list[right] = cid_key
quick_sort(array, cid_list, low, left - 1)
quick_sort(array, cid_list, left + 1, high)
return [array, cid_list]
if __name__ == '__main__':
test = [1, 5, 6, 2]
cid_list = [6, 5, 3, 8]
print(quick_sort(test, cid_list, 0, 3))
print(test)
print(cid_list)
网友评论