__author__ = 'student'

'''
quicksort
step 1, choose one pivot, such as pivot=la[0]
step 2, scan the data from right side, find data less than pivot, then swap this with pivot
pivot=1 [4] 5 7 3 20 9 [j]
then scan from left side, find data greater than pivot, then swap the position j and i
4 [] 7 3 20 9 5
when i>=j then finish one loop. then put the pivot in the i;
all data are dived by pivot now. left is less than pivot and right are greater than pivot.
think step by step then do it and try something
step 3. then you have two parts to sort, left part and right part.
recursive call this method to sort
'''
import random def quicksort(la,l,r):
if l>=r :
return
left=l;right=r
pivot=la[left]
while left < right:
while left<right and la[right]>pivot:
right-=1
if left<right :
la[left]=la[right]
left+=1
while left<right and la[left]<pivot:
left+=1
if left<right:
la[right]=la[left]
la[left]=pivot
quicksort(la,l,left-1)
quicksort(la,left+1,r) def quicksort2(la):
if len(la)<=1:
return la
return quicksort2([lt for lt in la[1:] if lt<la[0]])+ la[0:1]+quicksort2([ge for ge in la[1:] if ge>=la[0]]) import sys
sys.setrecursionlimit(999) la=[]
def generatenumbers(la,len):
for x in range(len):
la.extend([random.randint(1,50)])
generatenumbers(la,1000)
print la
quicksort(la,0,len(la)-1)
print la

最新文章

  1. [Exchange 2013]创建约会和会议
  2. Put your application in production
  3. android studio-创建第一个项目
  4. 用过的一个jquery插件实现转盘效果还不错手机兼容
  5. Bad configuration option localCommand
  6. 容联云通讯_提供网络通话、视频通话、视频会议、云呼叫中心、IM等融合通讯能力开放平台。
  7. Android热补丁动态修复
  8. Apache开启expires响应头,优化缓存
  9. HDU 4642 (13.08.25)
  10. tomcat环境变量的配置(网上摘,全部验证通过)
  11. poj1459 Power Network --- 最大流 EK/dinic
  12. input输入框只允许输入数字/ 数字+小数点/ 文字+字母/ 等解决方法
  13. Angular-ui-router+ocLazyLoad.js应用实例
  14. vue进阶--外卖商家页
  15. ReactNative 学习笔记
  16. C# 事务 四种事务隔离级别
  17. [转载]WIKI MVC模式
  18. Sublime Text 之运行 js 方法[2015-5-6更新mac下执行js]
  19. 少走弯路,一个老程序猿谈PHP职业发展规划
  20. 将tomcat以普通用户启动

热门文章

  1. 使用Windows PE的U盘安装win7
  2. asp.net 网页抓取内容
  3. 将C1Chart数据导出到Excel
  4. 在phpwind内容页使用百度分享进行图片分享
  5. 基于 ANSIBLE 自动化运维实践
  6. 浅谈一下缓存策略以及memcached 、redis区别
  7. 依赖于spring 4.x的spring组件
  8. 六个创建模式之单例模式(Singleton Pattern)
  9. jquery只能输入数字方法
  10. 微信公共平台开发3 .net