#-*-coding:utf8-*-
import random
a=[]
b=[]
def init_array():
for i in range(10000):
v = random.randint(1,10000)
a.append(v)
b.append(v) #冒泡
def sort_array(a):
for i in range(len(a)):
for j in range(i+1,len(a)):
if a[i] > a[j]:
i_v = a[i]
a[i]=a[j]
a[j]=i_v #快排
def quick_sort(a,left,right):
if left < right:
key = a[left]
low = left
high = right
while low<high:
while low<high and a[high]>=key:
high-=1
a[low] = a[high]
while low<high and a[low]<=key:
low+=1
a[high]=a[low]
a[low]=key
quick_sort(a,left,low-1)
quick_sort(a,low+1,right) init_array() print "a",len(a)
print "b",len(b) sort_array(a)
quick_sort(b,0,len(b)-1) print a,len(a)
print b,len(b) 以上保存为 sort.py,然后:
python  -m cProfile  sort.py 冒泡时间复杂度O(n^2)
快排最差O(n^2),平均O(n*lgn)

最新文章

  1. 李洪强iOS经典面试题156 - Runtime详解(面试必备)
  2. windows2003安装证书服务:csp配置不正确、您没有此密钥容器的写访问权限
  3. CSS3-样式继承,层叠管理,文本格式化
  4. linux 中的斜杠 ‘/’ ‘\’ 的区别 - 服务器是LINUX的注意了, 和windows 的不一样哦!
  5. 笔记:ASP.NET MVC安全
  6. mysql 远程访问授权
  7. 编写一函数用来实现左右循环移位。函数原型为move(value,n);n&gt;0时右移n位,n&lt;0时左移|n|位。
  8. 浅析Android中的消息机制
  9. pyqt 简单判断指定的内容强度(比如帐号)
  10. 配置Raspbian 启用SPI I2C
  11. C++模板:字典树
  12. Android(Lollipop/5.0) Material Design(六) 使用图像
  13. 2. SQL Server数据库状态监控 - 错误日志
  14. ontimer 与多线程
  15. 2014NOIP普及组 子矩阵
  16. cmd代码:查端口占用,查进程号,杀进程
  17. 有了这8款Mac安全杀毒和流氓防护软件,让你的mac清理优化,更加安全
  18. win10家庭版多用户
  19. 最新版Kali Linux虚拟机安装Open-vm-tools替代VMware tools
  20. C# 读取sqlite文件

热门文章

  1. 设计模式8---适配器模式(Adapter)
  2. NIOS II SOPC系统自定义IP常见知识点总结
  3. Python 数据分析—第七章 数据归整:清理、转换、合并、重塑
  4. MongoDB整理笔记のjava MongoDB分页优化
  5. Apache Shiro去掉URL中的JSESSIONID
  6. Mathcad操作tips:函数、符号计算
  7. 读《MacTalk&#183;人生元编程》
  8. 数独高阶技巧入门之三——Fish
  9. C#连接SQL server数据库
  10. java 通过ip获取客户端mac地址