算法导论上面快速排序的实现。

代码:

def partition(array, left, right):
i = left-1
for j in range(left, right):
if array[j] <= array[right]:
i += 1
array[j], array[i] = array[i], array[j]
array[i+1], array[right] = array[right], array[i+1]
return i+1 def quicksort(array, left, right):
if left < right:
pivot = partition(array, left, right)
quicksort(array, left, pivot-1)
quicksort(array, pivot+1, right) array = [3, 2, 1, 0, 9, 8, 7, 6, 5, 4]
quicksort(array, 0, 9)
print array

[算法导论]quicksort algorithm @ Python的更多相关文章

  1. 隐马尔科夫模型,第三种问题解法,维比特算法(biterbi) algorithm python代码

    上篇介绍了隐马尔科夫模型 本文给出关于问题3解决方法,并给出一个例子的python代码 回顾上文,问题3是什么, 下面给出,维比特算法(biterbi) algorithm 下面通过一个具体例子,来说 ...

  2. [算法导论]拓扑排序 @ Python

    class Graph: def __init__(self): self.V = [] class Vertex: def __init__(self, x): self.key = x self. ...

  3. [算法导论]强连通分量 @ Python

    class Graph: def __init__(self): self.V = [] class Vertex: def __init__(self, x): self.key = x self. ...

  4. [算法导论]merge sort @ Python

    import sys class mergesort(): def merge_sort(self, A, p, r): if p < r: q = (p + r) / 2 self.merge ...

  5. [Algorithm] 如何正确撸<算法导论>CLRS

    其实算法本身不难,第一遍可以只看伪代码和算法思路.如果想进一步理解的话,第三章那些标记法是非常重要的,就算要花费大量时间才能理解,也不要马马虎虎略过.因为以后的每一章,讲完算法就是这样的分析,精通的话 ...

  6. quickSort算法导论版实现

    本文主要实践一下算法导论上的快排算法,活动活动. 伪代码图来源于 http://www.cnblogs.com/dongkuo/p/4827281.html // imp the quicksort ...

  7. MIT算法导论——第一讲.Analysis of algorithm

    本栏目(Algorithms)下MIT算法导论专题是个人对网易公开课MIT算法导论的学习心得与笔记.所有内容均来自MIT公开课Introduction to Algorithms中Charles E. ...

  8. MIT算法导论——第四讲.Quicksort

    本栏目(Algorithms)下MIT算法导论专题是个人对网易公开课MIT算法导论的学习心得与笔记.所有内容均来自MIT公开课Introduction to Algorithms中Charles E. ...

  9. 算法导论 第一章and第二章(python)

    算法导论 第一章 算法     输入--(算法)-->输出   解决的问题     识别DNA(排序,最长公共子序列,) # 确定一部分用法     互联网快速访问索引     电子商务(数值算 ...

随机推荐

  1. Codeforces.314E.Sereja and Squares(DP)

    题目链接 http://www.cnblogs.com/TheRoadToTheGold/p/8443668.html \(Description\) 给你一个擦去了部分左括号和全部右括号的括号序列, ...

  2. Xtreme9.0 - Taco Stand 数学

    Taco Stand 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/taco-stand Des ...

  3. Windows系列之(一):Windows10 上运行Ubuntu Bash

    1. 前言 2016年4月6日,Windows 10 Insider Preview 发布的版本 14316,添加了Ubuntu Bash,在Windows上提供一个Linux环境,可以直接执行Lin ...

  4. git 仓库迁移,git remote 更改源

    git仓库迁移 我们有时候需要迁移git仓库,但又想保留每次commit的记录,所以我们只需要更改git remote [源]的问题即可 首先查看你的remote的地址 git remote -vv ...

  5. web网页上面调用qq

    <a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=2812415198&site=q ...

  6. STM32F1XX devices vector table for EWARM toolchain.

    ;******************** (C) COPYRIGHT 2014 STMicroelectronics ******************* ;* File Name : start ...

  7. Java-JVM-GC

    http://www.cnblogs.com/zhguang/p/Java-JVM-GC.html

  8. man命令使用

    如:man 2 read, 就可以查看read函数的文档

  9. Delphi XE2 compiler performance

    原文: http://blog.barrkel.com/2011/10/delphi-xe2-compiler-performance.html Delphi XE2 compiler perform ...

  10. delphi 取得任意程序的命令行

    program GetCommandLineExDemo; uses Windows; constSystemHandleInformation = 16;ProcessBasicInformatio ...