##快排思路
简单来说,就是找一个key值作为参考值,每次都找第一个。然后,用一个临时变量存参考值,再从头到尾,逐个比较比参考值小的,换值,i++:从后往前,比较比参考值大的,换值j−-。直到i=j退出
1、先从数列中取出一个数作为基准数
2、分区过程,将比这个数大的数全放到它的右边,小于或等于它的数全放到它的左边
3、再对左右区间重复第二步,直到各区间只有一个数
#coding=utf-8
import sys
import math
def partion(nums,left,right): #partion
key = nums[left];
low = left;
high = right;
while low < high:
while(low < high) and (nums[high] >=key):
high = high -1;
nums[low] = nums[high];
while(low < high) and (nums[high] <=key):
low = low +1;
nums[high] = nums[low];
nums[low] = key;
return low
def quicksort(nums,left,right):#quicksort
if left
p = partion(nums,left,right);
quicksort(nums,left,p-1);
quicksort(nums,p+1,right);#递归操作
return nums;
if __name__ == "__main__":
a= raw_input();
nums=[];
for i in a.split(' '):
nums.append(int(i));
right = len(nums)-1;
left = 0;
ans = quicksort(nums,left,right);
print ans;